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

Introduce new configuration for limiting replica's local replication buffer during dual-channel replication sync #915

Closed
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 @@ -3243,6 +3243,7 @@ standardConfig static_configs[] = {
createSizeTConfig("hll-sparse-max-bytes", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.hll_sparse_max_bytes, 3000, MEMORY_CONFIG, NULL, NULL),
createSizeTConfig("tracking-table-max-keys", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.tracking_table_max_keys, 1000000, INTEGER_CONFIG, NULL, NULL), /* Default: 1 million keys max. */
createSizeTConfig("client-query-buffer-limit", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, 1024 * 1024, LONG_MAX, server.client_max_querybuf_len, 1024 * 1024 * 1024, MEMORY_CONFIG, NULL, NULL), /* Default: 1GB max query buffer. */
createSizeTConfig("replicas-dual-channel-buffer-limit", NULL, DEBUG_CONFIG | MODIFIABLE_CONFIG, 0, LONG_MAX, server.pending_repl_data.limit_bytes, 1024 * 1024 * 1024, MEMORY_CONFIG, NULL, NULL), /* Default: 1GB max query buffer. */
createSSizeTConfig("maxmemory-clients", NULL, MODIFIABLE_CONFIG, -100, SSIZE_MAX, server.maxmemory_clients, 0, MEMORY_CONFIG | PERCENT_CONFIG, NULL, applyClientMaxMemoryUsage),

/* Other configs */
Expand Down
2 changes: 1 addition & 1 deletion src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ void bufferReplData(connection *conn) {
remaining_bytes = readIntoReplDataBlock(conn, tail, remaining_bytes);
}
if (readlen && remaining_bytes == 0) {
if (server.pending_repl_data.len > server.client_obuf_limits[CLIENT_TYPE_REPLICA].hard_limit_bytes) {
if (server.pending_repl_data.len > server.pending_repl_data.limit_bytes) {
serverLog(LL_NOTICE, "Replication buffer limit reached, stopping buffering.");
/* Stop accumulating primary commands. */
connSetReadHandler(conn, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ typedef struct replDataBuf {
list *blocks; /* List of replDataBufBlock */
size_t len; /* Number of bytes stored in all blocks */
size_t peak;
size_t limit_bytes; /* Configurable buffer limit */
} replDataBuf;

typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/dual-channel-replication.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ start_server {tags {"dual-channel-replication external:skip"}} {
# We expect that the next full sync will take 100 seconds (10k*10000)ms
# It will give us enough time to fill the replica buffer.
$replica1 config set dual-channel-replication-enabled yes
$replica1 config set client-output-buffer-limit "replica 16383 16383 0"
$replica1 config set replicas-dual-channel-buffer-limit "16383"

$replica1 replicaof $primary_host $primary_port
# Wait for replica to establish psync using main channel
Expand Down Expand Up @@ -356,7 +356,7 @@ start_server {tags {"dual-channel-replication external:skip"}} {
}

$replica1 replicaof no one
$replica1 config set client-output-buffer-limit "replica 256mb 256mb 0"; # remove repl buffer limitation
$replica1 config set replicas-dual-channel-buffer-limit [expr {1024 * 1024 * 1024}]; # remove repl buffer limitation
$primary config set rdb-key-save-delay 0

wait_for_condition 500 1000 {
Expand Down
7 changes: 7 additions & 0 deletions valkey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,13 @@ repl-diskless-load disabled
# server, which is typically handling more critical operations.
dual-channel-replication-enabled no

# This configuration option sets the maximum size of the local replication
# buffer on the replica during dual-channel-replication syncronization.
# The local replication buffer is used to store data received from the primary
# during the sync, before it is written to the replica's database.
#
# replicas-dual-channel-buffer-limit <bytes>

# Master send PINGs to its replicas in a predefined interval. It's possible to
# change this interval with the repl_ping_replica_period option. The default
# value is 10 seconds.
Expand Down
Loading