summaryrefslogtreecommitdiffstats
path: root/tests/cluster/tests/20-half-migrated-slot.tcl
blob: 229b3a86df82f51e6e10c537d623017293636756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Tests for fixing migrating slot at all stages:
# 1. when migration is half inited on "migrating" node
# 2. when migration is half inited on "importing" node
# 3. migration inited, but not finished
# 4. migration is half finished on "migrating" node
# 5. migration is half finished on "importing" node

# TODO: Test is currently disabled until it is stabilized (fixing the test
# itself or real issues in Redis).

if {false} {
source "../tests/includes/init-tests.tcl"
source "../tests/includes/utils.tcl"

test "Create a 2 nodes cluster" {
    create_cluster 2 0
    config_set_all_nodes cluster-allow-replica-migration no
}

test "Cluster is up" {
    assert_cluster_state ok
}

set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
catch {unset nodefrom}
catch {unset nodeto}

proc reset_cluster {} {
    uplevel 1 {
        $cluster refresh_nodes_map
        array set nodefrom [$cluster masternode_for_slot 609]
        array set nodeto [$cluster masternode_notfor_slot 609]
    }
}

reset_cluster

$cluster set aga xyz

test "Half init migration in 'migrating' is fixable" {
    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
    fix_cluster $nodefrom(addr)
    assert_equal "xyz" [$cluster get aga]
}

test "Half init migration in 'importing' is fixable" {
    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
    fix_cluster $nodefrom(addr)
    assert_equal "xyz" [$cluster get aga]
}

test "Init migration and move key" {
    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
    assert_equal {OK} [$nodefrom(link) migrate $nodeto(host) $nodeto(port) aga 0 10000]
    wait_for_cluster_propagation
    assert_equal "xyz" [$cluster get aga]
    fix_cluster $nodefrom(addr)
    assert_equal "xyz" [$cluster get aga]
}

reset_cluster

test "Move key again" {
    wait_for_cluster_propagation
    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
    assert_equal {OK} [$nodefrom(link) migrate $nodeto(host) $nodeto(port) aga 0 10000]
    wait_for_cluster_propagation
    assert_equal "xyz" [$cluster get aga]
}

test "Half-finish migration" {
    # half finish migration on 'migrating' node
    assert_equal {OK} [$nodefrom(link) cluster setslot 609 node $nodeto(id)]
    fix_cluster $nodefrom(addr)
    assert_equal "xyz" [$cluster get aga]
}

reset_cluster

test "Move key back" {
    # 'aga' key is in 609 slot
    assert_equal {OK} [$nodefrom(link) cluster setslot 609 migrating $nodeto(id)]
    assert_equal {OK} [$nodeto(link) cluster setslot 609 importing $nodefrom(id)]
    assert_equal {OK} [$nodefrom(link) migrate $nodeto(host) $nodeto(port) aga 0 10000]
    assert_equal "xyz" [$cluster get aga]
}

test "Half-finish importing" {
    # Now we half finish 'importing' node
    assert_equal {OK} [$nodeto(link) cluster setslot 609 node $nodeto(id)]
    fix_cluster $nodefrom(addr)
    assert_equal "xyz" [$cluster get aga]
}

config_set_all_nodes cluster-allow-replica-migration yes
}