]>
Commit | Line | Data |
---|---|---|
1 | start_server {tags {"repl"}} { | |
2 | start_server {} { | |
3 | test {First server should have role slave after SLAVEOF} { | |
4 | r -1 slaveof [srv 0 host] [srv 0 port] | |
5 | wait_for_condition 50 100 { | |
6 | [s -1 role] eq {slave} && | |
7 | [string match {*master_link_status:up*} [r -1 info replication]] | |
8 | } else { | |
9 | fail "Can't turn the instance into a slave" | |
10 | } | |
11 | } | |
12 | ||
13 | test {BRPOPLPUSH replication, when blocking against empty list} { | |
14 | set rd [redis_deferring_client] | |
15 | $rd brpoplpush a b 5 | |
16 | r lpush a foo | |
17 | wait_for_condition 50 100 { | |
18 | [r debug digest] eq [r -1 debug digest] | |
19 | } else { | |
20 | fail "Master and slave have different digest: [r debug digest] VS [r -1 debug digest]" | |
21 | } | |
22 | } | |
23 | ||
24 | test {BRPOPLPUSH replication, list exists} { | |
25 | set rd [redis_deferring_client] | |
26 | r lpush c 1 | |
27 | r lpush c 2 | |
28 | r lpush c 3 | |
29 | $rd brpoplpush c d 5 | |
30 | after 1000 | |
31 | assert_equal [r debug digest] [r -1 debug digest] | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
36 | start_server {tags {"repl"}} { | |
37 | r set mykey foo | |
38 | ||
39 | start_server {} { | |
40 | test {Second server should have role master at first} { | |
41 | s role | |
42 | } {master} | |
43 | ||
44 | test {SLAVEOF should start with link status "down"} { | |
45 | r slaveof [srv -1 host] [srv -1 port] | |
46 | s master_link_status | |
47 | } {down} | |
48 | ||
49 | test {The role should immediately be changed to "slave"} { | |
50 | s role | |
51 | } {slave} | |
52 | ||
53 | wait_for_sync r | |
54 | test {Sync should have transferred keys from master} { | |
55 | r get mykey | |
56 | } {foo} | |
57 | ||
58 | test {The link status should be up} { | |
59 | s master_link_status | |
60 | } {up} | |
61 | ||
62 | test {SET on the master should immediately propagate} { | |
63 | r -1 set mykey bar | |
64 | ||
65 | wait_for_condition 500 100 { | |
66 | [r 0 get mykey] eq {bar} | |
67 | } else { | |
68 | fail "SET on master did not propagated on slave" | |
69 | } | |
70 | } | |
71 | ||
72 | test {FLUSHALL should replicate} { | |
73 | r -1 flushall | |
74 | if {$::valgrind} {after 2000} | |
75 | list [r -1 dbsize] [r 0 dbsize] | |
76 | } {0 0} | |
77 | } | |
78 | } | |
79 | ||
80 | proc start_write_load {host port seconds} { | |
81 | exec tclsh8.5 tests/helpers/gen_write_load.tcl $host $port $seconds & | |
82 | } | |
83 | ||
84 | proc stop_write_load {handle} { | |
85 | catch {exec /bin/kill -9 $handle} | |
86 | } | |
87 | ||
88 | start_server {tags {"repl"}} { | |
89 | set master [srv 0 client] | |
90 | set master_host [srv 0 host] | |
91 | set master_port [srv 0 port] | |
92 | set slaves {} | |
93 | set load_handle0 [start_write_load $master_host $master_port 3] | |
94 | set load_handle1 [start_write_load $master_host $master_port 5] | |
95 | set load_handle2 [start_write_load $master_host $master_port 20] | |
96 | set load_handle3 [start_write_load $master_host $master_port 8] | |
97 | set load_handle4 [start_write_load $master_host $master_port 4] | |
98 | start_server {} { | |
99 | lappend slaves [srv 0 client] | |
100 | start_server {} { | |
101 | lappend slaves [srv 0 client] | |
102 | start_server {} { | |
103 | lappend slaves [srv 0 client] | |
104 | test "Connect multiple slaves at the same time (issue #141)" { | |
105 | # Send SALVEOF commands to slaves | |
106 | [lindex $slaves 0] slaveof $master_host $master_port | |
107 | [lindex $slaves 1] slaveof $master_host $master_port | |
108 | [lindex $slaves 2] slaveof $master_host $master_port | |
109 | ||
110 | # Wait for all the three slaves to reach the "online" state | |
111 | set retry 500 | |
112 | while {$retry} { | |
113 | set info [r -3 info] | |
114 | if {[string match {*slave0:*,online*slave1:*,online*slave2:*,online*} $info]} { | |
115 | break | |
116 | } else { | |
117 | incr retry -1 | |
118 | after 100 | |
119 | } | |
120 | } | |
121 | if {$retry == 0} { | |
122 | error "assertion:Slaves not correctly synchronized" | |
123 | } | |
124 | ||
125 | # Stop the write load | |
126 | stop_write_load $load_handle0 | |
127 | stop_write_load $load_handle1 | |
128 | stop_write_load $load_handle2 | |
129 | stop_write_load $load_handle3 | |
130 | stop_write_load $load_handle4 | |
131 | ||
132 | # Wait that slaves exit the "loading" state | |
133 | wait_for_condition 500 100 { | |
134 | ![string match {*loading:1*} [[lindex $slaves 0] info]] && | |
135 | ![string match {*loading:1*} [[lindex $slaves 1] info]] && | |
136 | ![string match {*loading:1*} [[lindex $slaves 2] info]] | |
137 | } else { | |
138 | fail "Slaves still loading data after too much time" | |
139 | } | |
140 | ||
141 | # Make sure that slaves and master have same number of keys | |
142 | wait_for_condition 500 100 { | |
143 | [$master dbsize] == [[lindex $slaves 0] dbsize] && | |
144 | [$master dbsize] == [[lindex $slaves 1] dbsize] && | |
145 | [$master dbsize] == [[lindex $slaves 2] dbsize] | |
146 | } else { | |
147 | fail "Different number of keys between masted and slave after too long time." | |
148 | } | |
149 | ||
150 | # Check digests | |
151 | set digest [$master debug digest] | |
152 | set digest0 [[lindex $slaves 0] debug digest] | |
153 | set digest1 [[lindex $slaves 1] debug digest] | |
154 | set digest2 [[lindex $slaves 2] debug digest] | |
155 | assert {$digest ne 0000000000000000000000000000000000000000} | |
156 | assert {$digest eq $digest0} | |
157 | assert {$digest eq $digest1} | |
158 | assert {$digest eq $digest2} | |
159 | } | |
160 | } | |
161 | } | |
162 | } | |
163 | } |