Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flushdb option for repl-diskless-load #909

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,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 ||
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 @@ -504,6 +504,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 @@ -1478,6 +1478,63 @@ 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
}
}
} {} {external:skip}
}

start_server {tags {"repl external:skip"}} {
set replica [srv 0 client]
$replica set replica_key replica_value
Expand Down
3 changes: 3 additions & 0 deletions valkey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,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
Loading