Skip to content

Commit 42951ab

Browse files
committed
Diskless replication: trigger a BGSAVE after a config change.
If we turn from diskless to disk-based replication via CONFIG SET, we need a way to start a BGSAVE if there are slaves alerady waiting for a BGSAVE to start. Normally with disk-based replication we do it as soon as the previous child exits, but when there is a configuration change via CONFIG SET, we may have slaves in WAIT_BGSAVE_START state without an RDB background process currently active.
1 parent 5f8360e commit 42951ab

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/replication.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -689,17 +689,20 @@ void sendBulkToSlave(aeEventLoop *el, int fd, void *privdata, int mask) {
689689
}
690690
}
691691

692-
/* This function is called at the end of every background saving.
693-
* The argument bgsaveerr is REDIS_OK if the background saving succeeded
694-
* otherwise REDIS_ERR is passed to the function.
695-
* The 'type' argument is the type of the child that terminated
696-
* (if it had a disk or socket target).
692+
/* This function is called at the end of every background saving,
693+
* or when the replication RDB transfer strategy is modified from
694+
* disk to socket or the other way around.
697695
*
698696
* The goal of this function is to handle slaves waiting for a successful
699697
* background saving in order to perform non-blocking synchronization, and
700698
* to schedule a new BGSAVE if there are slaves that attached while a
701699
* BGSAVE was in progress, but it was not a good one for replication (no
702-
* other slave was accumulating differences). */
700+
* other slave was accumulating differences).
701+
*
702+
* The argument bgsaveerr is REDIS_OK if the background saving succeeded
703+
* otherwise REDIS_ERR is passed to the function.
704+
* The 'type' argument is the type of the child that terminated
705+
* (if it had a disk or socket target). */
703706
void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
704707
listNode *ln;
705708
int startbgsave = 0;
@@ -722,8 +725,8 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
722725
* the slave online. */
723726
if (type == REDIS_RDB_CHILD_TYPE_SOCKET) {
724727
putSlaveOnline(slave);
725-
redisLog(REDIS_NOTICE,
726-
"Synchronization with slave succeeded (socket)");
728+
redisLog(REDIS_NOTICE,
729+
"Synchronization with slave succeeded (socket)");
727730
} else {
728731
if (bgsaveerr != REDIS_OK) {
729732
freeClient(slave);
@@ -1943,10 +1946,12 @@ void replicationCron(void) {
19431946

19441947
/* If we are using diskless replication and there are slaves waiting
19451948
* in WAIT_BGSAVE_START state, check if enough seconds elapsed and
1946-
* start one. */
1947-
if (server.repl_diskless_sync && server.rdb_child_pid == -1 &&
1948-
server.aof_child_pid == -1)
1949-
{
1949+
* start a BGSAVE.
1950+
*
1951+
* This code is also useful to trigger a BGSAVE if the diskless
1952+
* replication was turned off with CONFIG SET, while there were already
1953+
* slaves in WAIT_BGSAVE_START state. */
1954+
if (server.rdb_child_pid == -1 && server.aof_child_pid == -1) {
19501955
time_t idle, max_idle = 0;
19511956
int slaves_waiting = 0;
19521957
listNode *ln;

0 commit comments

Comments
 (0)