2019-07-12 03:54:41 -04:00
|
|
|
start_server {tags {"active-repl"} overrides {active-replica yes}} {
|
|
|
|
set slave [srv 0 client]
|
|
|
|
set slave_host [srv 0 host]
|
|
|
|
set slave_port [srv 0 port]
|
|
|
|
set slave_log [srv 0 stdout]
|
|
|
|
set slave_pid [s process_id]
|
2019-07-18 19:22:49 -04:00
|
|
|
|
|
|
|
start_server [list overrides [list active-replica yes replicaof [list $slave_host $slave_port]]] {
|
2019-07-12 03:54:41 -04:00
|
|
|
set master [srv 0 client]
|
|
|
|
set master_host [srv 0 host]
|
|
|
|
set master_port [srv 0 port]
|
2019-11-20 19:44:31 -05:00
|
|
|
set master_pid [s process_id]
|
2019-07-12 03:54:41 -04:00
|
|
|
|
|
|
|
# Use a short replication timeout on the slave, so that if there
|
|
|
|
# are no bugs the timeout is triggered in a reasonable amount
|
|
|
|
# of time.
|
|
|
|
$slave config set repl-timeout 5
|
2019-07-18 19:22:49 -04:00
|
|
|
$master config set repl-timeout 5
|
2019-07-12 03:54:41 -04:00
|
|
|
|
|
|
|
# Start the replication process...
|
|
|
|
$slave slaveof $master_host $master_port
|
2019-07-18 19:22:49 -04:00
|
|
|
#note the master is a replica via the config (see start_server above)
|
2019-07-12 03:54:41 -04:00
|
|
|
|
|
|
|
test {Active replicas report the correct role} {
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[string match *active-replica* [$slave role]]
|
|
|
|
} else {
|
|
|
|
fail "Replica0 does not report the correct role"
|
|
|
|
}
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[string match *active-replica* [$master role]]
|
|
|
|
} else {
|
|
|
|
fail "Replica1 does not report the correct role"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test {Active replicas propogate} {
|
|
|
|
$master set testkey foo
|
|
|
|
wait_for_condition 50 500 {
|
|
|
|
[string match *foo* [$slave get testkey]]
|
|
|
|
} else {
|
|
|
|
fail "replication failed to propogate"
|
|
|
|
}
|
|
|
|
|
|
|
|
$slave set testkey bar
|
|
|
|
wait_for_condition 50 500 {
|
|
|
|
[string match bar [$master get testkey]]
|
|
|
|
} else {
|
|
|
|
fail "replication failed to propogate in the other direction"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:31:02 -04:00
|
|
|
test {Active replicas propogate binary} {
|
|
|
|
$master set binkey "\u0000foo"
|
|
|
|
wait_for_condition 50 500 {
|
|
|
|
[string match *foo* [$slave get binkey]]
|
|
|
|
} else {
|
|
|
|
fail "replication failed to propogate binary data"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 03:54:41 -04:00
|
|
|
test {Active replicas WAIT} {
|
|
|
|
# Test that wait succeeds since replicas should be syncronized
|
|
|
|
$master set testkey foo
|
|
|
|
$slave set testkey2 test
|
2019-07-12 23:52:07 -04:00
|
|
|
assert_equal {1} [$master wait 1 1000] { "value should propogate
|
|
|
|
within 1 second" }
|
|
|
|
assert_equal {1} [$slave wait 1 1000] { "value should propogate
|
|
|
|
within 1 second" }
|
2019-07-12 03:54:41 -04:00
|
|
|
|
|
|
|
# Now setup a situation where wait should fail
|
|
|
|
exec kill -SIGSTOP $slave_pid
|
|
|
|
$master set testkey fee
|
2019-07-12 23:52:07 -04:00
|
|
|
assert_equal {0} [$master wait 1 1000] { "slave shouldn't be
|
|
|
|
synchronized since its stopped" }
|
2019-07-12 03:54:41 -04:00
|
|
|
}
|
|
|
|
# Resume the replica we paused in the prior test
|
|
|
|
exec kill -SIGCONT $slave_pid
|
|
|
|
|
|
|
|
test {Active replica expire propogates} {
|
|
|
|
$master set testkey1 foo
|
|
|
|
wait_for_condition 50 1000 {
|
|
|
|
[string match *foo* [$slave get testkey1]]
|
|
|
|
} else {
|
|
|
|
fail "Replication failed to propogate"
|
|
|
|
}
|
|
|
|
$master pexpire testkey1 200
|
|
|
|
after 1000
|
2019-07-12 23:52:07 -04:00
|
|
|
assert_equal {0} [$master del testkey1] {"master expired"}
|
|
|
|
assert_equal {0} [$slave del testkey1] {"slave expired"}
|
2019-07-12 03:54:41 -04:00
|
|
|
|
|
|
|
$slave set testkey1 foo px 200
|
|
|
|
after 1000
|
|
|
|
assert_equal {0} [$master del testkey1]
|
|
|
|
assert_equal {0} [$slave del testkey1]
|
|
|
|
}
|
2019-09-28 14:59:44 -04:00
|
|
|
|
2019-11-20 19:44:31 -05:00
|
|
|
test {Active replica expire propogates when source is down} {
|
|
|
|
$slave flushall
|
|
|
|
$slave set testkey2 foo
|
|
|
|
$slave set testkey1 foo
|
|
|
|
wait_for_condition 50 1000 {
|
|
|
|
[string match *foo* [$master get testkey1]]
|
|
|
|
} else {
|
|
|
|
fail "Replication failed to propogate"
|
|
|
|
}
|
|
|
|
$slave expire testkey1 2
|
|
|
|
assert_equal {1} [$slave wait 1 500] { "value should propogate
|
|
|
|
within 0.5 seconds" }
|
|
|
|
exec kill -SIGSTOP $slave_pid
|
|
|
|
after 3000
|
|
|
|
# Ensure testkey1 is gone. Note, we can't do this directly as the normal commands lie to us
|
|
|
|
# about what is actually in the dict. The only way to know is with a count from info
|
|
|
|
assert_equal {1} [expr [string first {keys=1} [$master info keyspace]] >= 0] {"slave expired"}
|
|
|
|
}
|
|
|
|
exec kill -SIGCONT $slave_pid
|
|
|
|
|
2019-09-28 14:59:44 -04:00
|
|
|
test {Active replica different databases} {
|
|
|
|
$master select 3
|
|
|
|
$master set testkey abcd
|
|
|
|
$master select 2
|
|
|
|
$master del testkey
|
|
|
|
$slave select 3
|
|
|
|
wait_for_condition 50 1000 {
|
|
|
|
[string match abcd [$slave get testkey]]
|
|
|
|
} else {
|
|
|
|
fail "Replication failed to propogate DB 3"
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 03:54:41 -04:00
|
|
|
}
|
|
|
|
}
|