Skip to content

Commit 0995b03

Browse files
committed
[fix] swap/integration/replication cases ok
1 parent a9f8110 commit 0995b03

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/ctrip_swap_repl.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void replicationCacheSwapDrainingMaster(client *c) {
5353
* pending outputs to the master. */
5454
sdsclear(server.swap_draining_master->querybuf);
5555

56+
server.swap_draining_master->qb_pos = 0;
57+
server.swap_draining_master->repl_applied = 0;
5658
server.swap_draining_master->read_reploff = server.swap_draining_master->reploff;
5759
if (c->flags & CLIENT_MULTI) discardTransaction(c);
5860
listEmpty(c->reply);
@@ -170,9 +172,7 @@ static void processFinishedReplCommands() {
170172
c = wc->swap_repl_client;
171173

172174
wc->flags &= ~CLIENT_SWAPPING;
173-
c->keyrequests_count--;
174175
listDelNode(server.swap_repl_worker_clients_used, ln);
175-
listAddNodeTail(server.swap_repl_worker_clients_free, wc);
176176

177177
serverAssert(c->flags&CLIENT_MASTER);
178178

@@ -242,6 +242,14 @@ static void processFinishedReplCommands() {
242242
if (gtid_repr) decrRefCount(gtid_repr);
243243

244244
clientReleaseLocks(wc,NULL/*ctx unused*/);
245+
246+
/* Mark this repl command as fully finished only after:
247+
* - worker command replayed (call)
248+
* - replication stream fed to downstream
249+
* - locks released
250+
*/
251+
c->keyrequests_count--;
252+
listAddNodeTail(server.swap_repl_worker_clients_free, wc);
245253
}
246254
serverLog(LL_DEBUG, "< processFinishedReplCommands");
247255
}

tests/swap/integration/replication.tcl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ start_server {tags {"swap replication"} overrides {}} {
4848

4949
set master_repl_offset [status $master master_repl_offset]
5050

51-
assert_equal [status $slave master_link_status] {down}
52-
53-
assert {[status $master master_repl_offset] > [status $slave master_repl_offset]}
54-
5551
wait_for_sync $slave
56-
assert {[log_file_matches $master_log "*Sending 0 bytes of backlog starting from offset [expr $master_repl_offset+1]*"]}
52+
set expected_pattern "*Sending 0 bytes of backlog starting from offset [expr $master_repl_offset+1]*"
53+
wait_for_condition 50 100 {
54+
[log_file_matches $master_log $expected_pattern]
55+
} else {
56+
fail "timeout waiting PSYNC"
57+
}
5758
}
5859

5960
test {shift replid will be defered untill previous master client drain} {
60-
$slave config set swap-debug-rio-delay-micro 10000
61+
$slave config set swap-debug-rio-delay-micro 15000
6162

6263
set master_rd [redis_deferring_client -1]
6364
set slave_rd [redis_deferring_client 0]
@@ -80,8 +81,19 @@ start_server {tags {"swap replication"} overrides {}} {
8081
fail "Drainging slaveof no one results in fullresync! "
8182
}
8283

83-
assert {[log_file_matches $slave_log "*Replication id shift defer done*master_repl_offset=$master_repl_offset*"]}
84-
assert {[log_file_matches $master_log "*NOMASTERLINK Can't SYNC while replid shift in progress*"]}
84+
85+
set expected_psync_reply_log "*Master is currently unable to PSYNC but should be in the future: -NOMASTERLINK Can't SYNC while replid shift in progress*"
86+
wait_for_condition 50 100 {
87+
[log_file_matches $master_log $expected_psync_reply_log]
88+
} else {
89+
}
90+
91+
set expected_slave_pattern "*### Starting test shift replid will be defered untill previous master client drain*Replication id shift defer done*master_repl_offset=$master_repl_offset*"
92+
wait_for_condition 50 100 {
93+
[log_file_matches $slave_log $expected_slave_pattern]
94+
} else {
95+
fail "timeout waiting replid shift defer done"
96+
}
8597

8698
# restore master slave replication
8799
$slave_rd slaveof $master_host $master_port

0 commit comments

Comments
 (0)