Skip to content

Commit

Permalink
add flushdb option for repl-diskless-load
Browse files Browse the repository at this point in the history
Signed-off-by: kronwerk <>
Signed-off-by: kronwerk <[email protected]>
  • Loading branch information
kronwerk authored and kronwerk committed Aug 14, 2024
1 parent 131857e commit 7eccdd3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ configEnum shutdown_on_sig_enum[] = {{"default", 0}, {"save", SHUTDOWN_SA
configEnum repl_diskless_load_enum[] = {{"disabled", REPL_DISKLESS_LOAD_DISABLED},
{"on-empty-db", REPL_DISKLESS_LOAD_WHEN_DB_EMPTY},
{"swapdb", REPL_DISKLESS_LOAD_SWAPDB},
{"flushdb", REPL_DISKLESS_LOAD_FLUSHDB},
{NULL, 0}};

configEnum tls_auth_clients_enum[] = {{"no", TLS_CLIENT_AUTH_NO},
Expand Down
2 changes: 1 addition & 1 deletion src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ void restartAOFAfterSYNC(void) {

static int useDisklessLoad(void) {
/* compute boolean decision to use diskless load */
int enabled = server.repl_diskless_load == REPL_DISKLESS_LOAD_SWAPDB ||
int enabled = server.repl_diskless_load == REPL_DISKLESS_LOAD_SWAPDB || server.repl_diskless_load == REPL_DISKLESS_LOAD_FLUSHDB ||
(server.repl_diskless_load == REPL_DISKLESS_LOAD_WHEN_DB_EMPTY && dbTotalServerKeyCount() == 0);

if (enabled) {
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ typedef enum {
#define REPL_DISKLESS_LOAD_DISABLED 0
#define REPL_DISKLESS_LOAD_WHEN_DB_EMPTY 1
#define REPL_DISKLESS_LOAD_SWAPDB 2
#define REPL_DISKLESS_LOAD_FLUSHDB 3

/* TLS Client Authentication */
#define TLS_CLIENT_AUTH_NO 0
Expand Down
57 changes: 57 additions & 0 deletions tests/integration/replication.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1477,3 +1477,60 @@ start_server {tags {"repl external:skip"}} {
}
}
}

foreach dualchannel {yes no} {
test "replica actually flushes db if use diskless load with flushdb dual-channel-replication-enabled=$dualchannel" {
start_server {tags {"repl"}} {
set replica [srv 0 client]
set replica_log [srv 0 stdout]
start_server {} {
set master [srv 0 client]
set master_host [srv 0 host]
set master_port [srv 0 port]

# Fill both replica and master with data
$master debug populate 100 master 100000
$replica debug populate 201 replica 100000
assert_equal [$replica dbsize] 201
# Set up master
$master config set save ""
$master config set rdbcompression no
$master config set repl-diskless-sync yes
$master config set repl-diskless-sync-delay 0
$master config set dual-channel-replication-enabled $dualchannel
# Set master with a slow rdb generation, so that we can easily intercept loading
# 10ms per key, with 1000 keys is 10 seconds
$master config set rdb-key-save-delay 10000
# Set up replica
$replica config set save ""
$replica config set repl-diskless-load flushdb
$replica config set dual-channel-replication-enabled $dualchannel
# Start the replication process...
$replica replicaof $master_host $master_port

wait_for_condition 100 100 {
[s -1 loading] eq 1
} else {
fail "Replica didn't start loading"
}

# Make sure that next sync will not start immediately so that we can catch the replica in between syncs
$master config set repl-diskless-sync-delay 5

# Kill the replica connection on the master
set killed [$master client kill type replica]

wait_for_condition 100 100 {
[s -1 loading] eq 0
} else {
fail "Replica didn't disconnect"
}

assert_equal [$replica dbsize] 0

# Speed up shutdown
$master config set rdb-key-save-delay 0
}
}
}
}
3 changes: 3 additions & 0 deletions valkey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ repl-diskless-sync-max-replicas 0
# "on-empty-db" - Use diskless load only when current dataset is empty. This is
# safer and avoid having old and new dataset loaded side by side
# during replication.
# "flushdb" - Flush the current db contents before parsing. Note that if
# there's a problem before the replication succeeded you may
# lose all your data.
repl-diskless-load disabled

# This dual channel replication sync feature optimizes the full synchronization process
Expand Down

0 comments on commit 7eccdd3

Please sign in to comment.