summaryrefslogtreecommitdiff
path: root/src/replication.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-09-19 23:03:39 +0200
committerantirez <antirez@gmail.com>2017-09-19 23:03:39 +0200
commitc1c99e9f4e19b3c68d810a51449b34c2261e24c9 (patch)
treeaab16aca2971a4602cb4cb1352d7f79fe158f9a3 /src/replication.c
parenta4152119c6c13e5a8940513e0983e02d5c5545f2 (diff)
downloadredis-c1c99e9f4e19b3c68d810a51449b34c2261e24c9.tar.gz
PSYNC2: Fix the way replication info is saved/loaded from RDB.
This commit attempts to fix a number of bugs reported in #4316. They are related to the way replication info like replication ID, offsets, and currently selected DB in the master client, are stored and loaded by Redis. In order to avoid inconsistencies the changes in this commit try to enforce that: 1. Replication information are only stored when the RDB file is generated by a slave that has a valid 'master' client, so that we can always extract the currently selected DB. 2. When replication informations are persisted in the RDB file, all the info for a successful PSYNC or nothing is persisted. 3. The RDB replication informations are only loaded if the instance is configured as a slave, otherwise a master can start with IDs that relate to a different history of the data set, and stil retain such IDs in the future while receiving unrelated writes.
Diffstat (limited to 'src/replication.c')
-rw-r--r--src/replication.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/replication.c b/src/replication.c
index 97ce9608d..2b2673a4b 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -569,18 +569,12 @@ int startBgsaveForReplication(int mincapa) {
serverLog(LL_NOTICE,"Starting BGSAVE for SYNC with target: %s",
socket_target ? "slaves sockets" : "disk");
- rdbSaveInfo rsi = RDB_SAVE_INFO_INIT;
- /* If we are saving for a chained slave (that is, if we are,
- * in turn, a slave of another instance), make sure after
- * loadig the RDB, our slaves select the right DB: we'll just
- * send the replication stream we receive from our master, so
- * no way to send SELECT commands. */
- if (server.master) rsi.repl_stream_db = server.master->db->id;
-
+ rdbSaveInfo rsi, *rsiptr;
+ rsiptr = rdbPopulateSaveInfo(&rsi);
if (socket_target)
- retval = rdbSaveToSlavesSockets(&rsi);
+ retval = rdbSaveToSlavesSockets(rsiptr);
else
- retval = rdbSaveBackground(server.rdb_filename,&rsi);
+ retval = rdbSaveBackground(server.rdb_filename,rsiptr);
/* If we failed to BGSAVE, remove the slaves waiting for a full
* resynchorinization from the list of salves, inform them with