Skip to content

Commit

Permalink
fix psync stat error count
Browse files Browse the repository at this point in the history
rdb channel sync should also count psync failures.
This commit fix tests "replication partial resync" to run with rdb
channel enabled
  • Loading branch information
amitnagl committed May 19, 2024
1 parent a51b0a5 commit 97894e3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
13 changes: 7 additions & 6 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,6 @@ void syncCommand(client *c) {
if (masterTryPartialResynchronization(c, psync_offset) == C_OK) {
server.stat_sync_partial_ok++;
return; /* No full resync needed, return. */
} else if (c->flags & CLIENT_REPL_MAIN_CHANNEL) {
serverLog(LL_NOTICE,"Replica %s is marked as main-conn, and psync isn't possible. Full sync will continue with dedicated RDB connection.", replicationGetSlaveName(c));
if (connWrite(c->conn,"-FULLSYNCNEEDED\r\n",17) != 17) {
freeClientAsync(c);
}
return;
} else {
char *master_replid = c->argv[1]->ptr;

Expand All @@ -1125,6 +1119,13 @@ void syncCommand(client *c) {
* resync on purpose when they are not able to partially
* resync. */
if (master_replid[0] != '?') server.stat_sync_partial_err++;
if (c->flags & CLIENT_REPL_MAIN_CHANNEL) {
serverLog(LL_NOTICE,"Replica %s is marked as main-conn, and psync isn't possible. Full sync will continue with dedicated RDB connection.", replicationGetSlaveName(c));
if (connWrite(c->conn,"-FULLSYNCNEEDED\r\n",17) != 17) {
freeClientAsync(c);
}
return;
}
}
} else {
/* If a slave uses SYNC, we are dealing with an old implementation
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/gen_write_load.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ proc gen_write_load {host port seconds tls key} {
$r client setname LOAD_HANDLER
$r select 9
while 1 {
if {$key == 0} {
if {$key == ""} {
$r set [expr rand()] [expr rand()]
} else {
$r set $key [expr rand()]
Expand Down
42 changes: 25 additions & 17 deletions tests/integration/replication-psync.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# If reconnect is > 0, the test actually try to break the connection and
# reconnect with the master, otherwise just the initial synchronization is
# checked for consistency.
proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl reconnect} {
proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl rdbchann reconnect} {
start_server {tags {"repl"} overrides {save {}}} {
start_server {overrides {save {}}} {

Expand All @@ -21,7 +21,9 @@ proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl reco
$master config set repl-backlog-ttl $backlog_ttl
$master config set repl-diskless-sync $mdl
$master config set repl-diskless-sync-delay 1
$master config set repl-rdb-channel $rdbchann
$slave config set repl-diskless-load $sdl
$slave config set repl-rdb-channel $rdbchann

set load_handle0 [start_bg_complex_data $master_host $master_port 9 100000]
set load_handle1 [start_bg_complex_data $master_host $master_port 11 100000]
Expand All @@ -46,8 +48,8 @@ proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl reco
}
}

test "Test replication partial resync: $descr (diskless: $mdl, $sdl, reconnect: $reconnect)" {
# Now while the clients are writing data, break the maste-slave
test "Test replication partial resync: $descr (diskless: $mdl, $sdl, rdb-channel: $rdbchann, reconnect: $reconnect)" {
# Now while the clients are writing data, break the master-slave
# link multiple times.
if ($reconnect) {
for {set j 0} {$j < $duration*10} {incr j} {
Expand Down Expand Up @@ -99,6 +101,10 @@ proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl reco
fail "Master - Replica inconsistency, Run diff -u against /tmp/repldump*.txt for more info"
}
assert {[$master dbsize] > 0}
# if {$descr == "no backlog" && $mdl == "yes" && $sdl == "disabled"} {
# puts "Master port: $master_port"
# after 100000000
# }
eval $cond
}
}
Expand All @@ -108,24 +114,26 @@ proc test_psync {descr duration backlog_size backlog_ttl delay cond mdl sdl reco
tags {"external:skip"} {
foreach mdl {no yes} {
foreach sdl {disabled swapdb} {
test_psync {no reconnection, just sync} 6 1000000 3600 0 {
} $mdl $sdl 0
foreach rdbchann {yes no} {
test_psync {no reconnection, just sync} 6 1000000 3600 0 {
} $mdl $sdl $rdbchann 0

test_psync {ok psync} 6 100000000 3600 0 {
assert {[s -1 sync_partial_ok] > 0}
} $mdl $sdl 1
test_psync {ok psync} 6 100000000 3600 0 {
assert {[s -1 sync_partial_ok] > 0}
} $mdl $sdl $rdbchann 1

test_psync {no backlog} 6 100 3600 0.5 {
assert {[s -1 sync_partial_err] > 0}
} $mdl $sdl 1
test_psync {no backlog} 6 100 3600 0.5 {
assert {[s -1 sync_partial_err] > 0}
} $mdl $sdl $rdbchann 1

test_psync {ok after delay} 3 100000000 3600 3 {
assert {[s -1 sync_partial_ok] > 0}
} $mdl $sdl 1
test_psync {ok after delay} 3 100000000 3600 3 {
assert {[s -1 sync_partial_ok] > 0}
} $mdl $sdl $rdbchann 1

test_psync {backlog expired} 3 100000000 1 3 {
assert {[s -1 sync_partial_err] > 0}
} $mdl $sdl 1
test_psync {backlog expired} 3 100000000 1 3 {
assert {[s -1 sync_partial_err] > 0}
} $mdl $sdl $rdbchann 1
}
}
}
}
2 changes: 1 addition & 1 deletion tests/integration/replication.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ start_server {tags {"repl rdb-channel external:skip"}} {
}
}
if {$max_retry == 0} {
error "assertion:Replica not correctly synchronized"
error "assertion:Replica not in sync after 5 seconds"
}
}
stop_write_load $load_handle1
Expand Down
2 changes: 1 addition & 1 deletion tests/support/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ proc find_valgrind_errors {stderr on_termination} {
# of seconds to the specified the server instance.
proc start_write_load {host port seconds} {
set tclsh [info nameofexecutable]
exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds $::tls 0 &
exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds $::tls "" &
}

# Execute a background process writing only one key for the specified number
Expand Down

0 comments on commit 97894e3

Please sign in to comment.