From 6cba12397ba5bb471bc020b96071637ccbd13d0e Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 28 Feb 2018 12:31:50 +0100 Subject: WAIT AOF: deny if AOF is off. Trigger sync in proper place. --- src/replication.c | 9 ++++----- src/server.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/replication.c b/src/replication.c index 33e220766..ae254aff9 100644 --- a/src/replication.c +++ b/src/replication.c @@ -2404,6 +2404,10 @@ void waitCommand(client *c) { /* AOF or number of replicas argument parsing. */ if (!strcasecmp(c->argv[1]->ptr,"AOF")) { waitaof = 1; + if (server.aof_state != AOF_ON) { + addReplyError(c,"WAIT AOF is only allowed when AOF is enabled"); + return; + } } else { if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != C_OK) return; @@ -2495,11 +2499,6 @@ void processClientsBlockedInWait(void) { } } } - - /* If after this cycle we have still clients blocked, try to start - * a new AOF fsync. If one is already in progress nothig will happen. */ - if (server.blocked_clients_by_type[BLOCKED_AOF]) - aofStartBackgroundFsync(); } /* Return the slave replication offset for this instance, that is diff --git a/src/server.c b/src/server.c index 6bd19f578..819da25cc 100644 --- a/src/server.c +++ b/src/server.c @@ -1230,9 +1230,19 @@ void beforeSleep(struct aeEventLoop *eventLoop) { /* Unblock all the clients blocked for synchronous replication * or AOF sync in WAIT. */ - if (listLength(server.clients_waiting_acks)) + if (listLength(server.clients_waiting_acks)) { processClientsBlockedInWait(); + /* If after this cycle we have still clients blocked waiting for + * AOF fsync, try to start a new sync cycle. Note that if one is + * already in progress, the call does nothing. */ + if (server.blocked_clients_by_type[BLOCKED_AOF] && + server.aof_state == AOF_ON) + { + aofStartBackgroundFsync(); + } + } + /* Check if there are clients unblocked by modules that implement * blocking commands. */ moduleHandleBlockedClients(); -- cgit v1.2.1