summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhaozhao.zz <zhaozhao.zz@alibaba-inc.com>2017-11-22 12:05:30 +0800
committerantirez <antirez@gmail.com>2017-11-24 11:09:28 +0100
commit2eca8aed1422aa4daa7e4ab77511ecb0995ed958 (patch)
tree3e158b1ea7ae3397e13d5153f1378eb0bfeb8593
parent35942383507d0f54fceb8d1677ad1d408cc9da8f (diff)
downloadredis-2eca8aed1422aa4daa7e4ab77511ecb0995ed958.tar.gz
PSYNC2: make repl_stream_db never be -1
it means that after this change all the replication info in RDB is valid, and it can distinguish us from the older version.
-rw-r--r--src/rdb.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/rdb.c b/src/rdb.c
index 4f6cb592b..e5c0d093d 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -2046,15 +2046,12 @@ rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) {
* scenario which can make repl_stream_db be -1, that is the instance is
* a master, and it have repl_backlog, but server.slaveseldb is -1. */
if (!server.masterhost && server.repl_backlog) {
- rsi->repl_stream_db = server.slaveseldb;
- /* Note that server.slaveseldb may be -1, it means that this master
- * didn't apply any write commands after a full synchronization,
- * so we can leave the currently selected DB set to -1, because the
- * next write command must generate a SELECT statement. This allows
- * a restarted slave to reload replication ID/offset even the repl_stream_db
- * is -1, but we should not do that, because older implementations
- * may save a repl_stream_db as -1 in a wrong way. Maybe we can fix
- * it in the next release version. */
+ rsi->repl_stream_db = server.slaveseldb == -1 ? 0 : server.slaveseldb;
+ /* Note that when server.slaveseldb is -1, it means that this master
+ * didn't apply any write commands after a full synchronization.
+ * So we can let repl_stream_db be 0, this allows a restarted slave
+ * to reload replication ID/offset, it's safe because the next write
+ * command must generate a SELECT statement. */
return rsi;
}