Skip to content
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
6 changes: 5 additions & 1 deletion src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,11 @@ void replconfCommand(client *c) {
} else if (!strcasecmp(objectGetVal(c->argv[j]), "getack")) {
/* REPLCONF GETACK is used in order to request an ACK ASAP
* to the replica. */
if (server.primary_host && server.primary) replicationSendAck();
if (server.primary_host && server.primary) {
replicationSendAck();
if (server.fsynced_reploff != -1 && server.fsynced_reploff < c->repl_data->reploff)
server.repl_fack_wait_offset = c->repl_data->reploff;
}
return;
} else if (!strcasecmp(objectGetVal(c->argv[j]), "rdb-only")) {
/* REPLCONF RDB-ONLY is used to identify the client only wants
Expand Down
8 changes: 8 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,13 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
if (listLength(server.clients_waiting_acks) && prev_fsynced_reploff != server.fsynced_reploff) dont_sleep = 1;
}

/* A replica answers GETACK before it fsyncs what it acked, so report the fsync as soon as it
* happens instead of in the next periodic ACK. */
if (server.repl_fack_wait_offset != -1 && server.fsynced_reploff >= server.repl_fack_wait_offset) {
server.repl_fack_wait_offset = -1;
replicationSendAck();
}

/* Handle writes with pending output buffers. */
int client_writes = handleClientsWithPendingWrites();
if (client_writes > 0) server.el_iteration_active = true;
Expand Down Expand Up @@ -3151,6 +3158,7 @@ void initServer(void) {
server.pending_push_messages = listCreate();
server.clients_waiting_acks = listCreate();
server.get_ack_from_replicas = 0;
server.repl_fack_wait_offset = -1;
server.paused_actions = 0;
memset(server.client_pause_per_purpose, 0, sizeof(server.client_pause_per_purpose));
server.postponed_clients = listCreate();
Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,7 @@ struct valkeyServer {
* when it receives an error on the replication stream */
int repl_ignore_disk_write_error; /* Configures whether replicas panic when unable to
* persist writes to AOF. */
long long repl_fack_wait_offset; /* Send an ACK once fsynced_reploff reaches this, -1 if none. */

int repl_compression_advertised; /* Compression algorithm advertised in the current upstream
* handshake, or REPL_COMPRESSION_CAPA_UNKNOWN before REPLCONF capa. */
Expand Down Expand Up @@ -3466,6 +3467,7 @@ void freeReplicaReferencedReplBuffer(client *replica);
void replicationFeedMonitors(client *c, list *monitors, int dictid, robj **argv, int argc);
void updateReplicasWaitingBgsave(int bgsaveerr, int type);
void replicationCron(void);
void replicationSendAck(void);
void replicationStartPendingFork(void);
void replicationHandlePrimaryDisconnection(void);
void replicationCachePrimary(client *c);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/wait.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ tags {"wait aof network external:skip"} {
$replica config set appendfsync everysec
}

test {WAITAOF replica copy appendfsync always does not wait for the replica cron} {
test_config_set $replica appendfsync always
$master incr foo
assert_equal [$master waitaof 0 1 0] {1 1}

# Pipelined, so the replica gets the GETACK before it fsyncs the write. Its
# periodic ACK is once a second, so at most a few of these succeed without an
# ACK after the fsync.
set rd [valkey_deferring_client -1]
test_defer [list $rd close]
set timeout [expr {$::valgrind ? 1000 : 200}]
for {set i 0} {$i < 10} {incr i} {
$rd write [format_command incr foo]
$rd write [format_command waitaof 0 1 $timeout]
$rd flush
$rd read
assert_equal [$rd read] {1 1}
}
}

test {WAITAOF replica copy if replica is blocked} {
pause_process $replica_pid
$master incr foo
Expand Down
Loading