Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 596b71f

Browse files
committed
[Fix] Disable replication if persistence is not available.
Replication (including diskless replication) requires persistence to be available. This fix prevents a crash and returns "ERR unknown command" to the slave.
1 parent 607d6f9 commit 596b71f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/config.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,37 @@ void loadServerConfigFromString(char *config) {
588588
// ignore. This is taken care of in the win32_service code.
589589
} else if (!strcasecmp(argv[0], "persistence-available")) {
590590
if (strcasecmp(argv[1], "no") == 0) {
591-
//remove BGSAVE and BGREWRITEAOF when persistence is disabled
591+
// remove BGSAVE, BGREWRITEAOF and replication commands
592+
// when persistence is disabled
592593
int retval;
593594
sds bgsave;
594595
sds bgrewriteaof;
596+
sds replconf;
597+
sds psync;
598+
sds sync;
595599

596600
bgsave = sdsnew("bgsave");
597601
bgrewriteaof = sdsnew("bgrewriteaof");
602+
replconf = sdsnew("replconf");
603+
psync = sdsnew("psync");
604+
sync = sdsnew("sync");
598605

599606
retval = dictDelete(server.commands, bgsave);
600607
redisAssert(retval == DICT_OK);
601608
retval = dictDelete(server.commands, bgrewriteaof);
602609
redisAssert(retval == DICT_OK);
610+
retval = dictDelete(server.commands, replconf);
611+
redisAssert(retval == DICT_OK);
612+
retval = dictDelete(server.commands, psync);
613+
redisAssert(retval == DICT_OK);
614+
retval = dictDelete(server.commands, sync);
615+
redisAssert(retval == DICT_OK);
603616

604617
sdsfree(bgsave);
605618
sdsfree(bgrewriteaof);
619+
sdsfree(replconf);
620+
sdsfree(psync);
621+
sdsfree(sync);
606622
}
607623
#endif
608624
} else {

0 commit comments

Comments
 (0)