diff options
author | antirez <antirez@gmail.com> | 2016-11-10 12:35:29 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-11-10 12:35:29 +0100 |
commit | 28c96d73b2e157a37465560bc421280d17005708 (patch) | |
tree | 0843c6a1f22c38815eff7ab0638999ad8f5789a2 /src/rdb.c | |
parent | 4e5e366ed265f2571124edfa9c2f9eaa0d450c45 (diff) | |
download | redis-psync2.tar.gz |
PSYNC2: Save replication ID/offset on RDB file.psync2
This means that stopping a slave and restarting it will still make it
able to PSYNC with the master. Moreover the master itself will retain
its ID/offset, in case it gets turned into a slave, or if a slave will
try to PSYNC with it with an exactly updated offset (otherwise there is
no backlog).
This change was possible thanks to PSYNC v2 that makes saving the current
replication state much simpler.
Diffstat (limited to 'src/rdb.c')
-rw-r--r-- | src/rdb.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -855,6 +855,8 @@ int rdbSaveInfoAuxFields(rio *rdb, int flags, rdbSaveInfo *rsi) { } } if (rdbSaveAuxFieldStrInt(rdb,"aof-preamble",aof_preamble) == -1) return -1; + if (rdbSaveAuxFieldStrStr(rdb,"repl-id",server.replid) == -1) return -1; + if (rdbSaveAuxFieldStrInt(rdb,"repl-offset",server.master_repl_offset) == -1) return -1; return 1; } @@ -1513,6 +1515,13 @@ int rdbLoadRio(rio *rdb, rdbSaveInfo *rsi) { (char*)auxval->ptr); } else if (!strcasecmp(auxkey->ptr,"repl-stream-db")) { if (rsi) rsi->repl_stream_db = atoi(auxval->ptr); + } else if (!strcasecmp(auxkey->ptr,"repl-id")) { + if (rsi && sdslen(auxval->ptr) == CONFIG_RUN_ID_SIZE) { + memcpy(rsi->repl_id,auxval->ptr,CONFIG_RUN_ID_SIZE+1); + rsi->repl_id_is_set = 1; + } + } else if (!strcasecmp(auxkey->ptr,"repl-offset")) { + if (rsi) rsi->repl_offset = strtoll(auxval->ptr,NULL,10); } else { /* We ignore fields we don't understand, as by AUX field * contract. */ |