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/server.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/server.c')
-rw-r--r-- | src/server.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/server.c b/src/server.c index b94490a33..d17ded9b0 100644 --- a/src/server.c +++ b/src/server.c @@ -3423,9 +3423,20 @@ void loadDataFromDisk(void) { if (loadAppendOnlyFile(server.aof_filename) == C_OK) serverLog(LL_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000); } else { - if (rdbLoad(server.rdb_filename,NULL) == C_OK) { + rdbSaveInfo rsi = RDB_SAVE_INFO_INIT; + if (rdbLoad(server.rdb_filename,&rsi) == C_OK) { serverLog(LL_NOTICE,"DB loaded from disk: %.3f seconds", (float)(ustime()-start)/1000000); + + /* Restore the replication ID / offset from the RDB file. */ + if (rsi.repl_id_is_set && rsi.repl_offset != -1) { + memcpy(server.replid,rsi.repl_id,sizeof(server.replid)); + server.master_repl_offset = rsi.repl_offset; + /* If we are a slave, create a cached master from this + * information, in order to allow partial resynchronizations + * with masters. */ + if (server.masterhost) replicationCacheMasterUsingMyself(); + } } else if (errno != ENOENT) { serverLog(LL_WARNING,"Fatal error loading the DB: %s. Exiting.",strerror(errno)); exit(1); |