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.
This commit is contained in:
zhaozhao.zz 2017-11-22 12:05:30 +08:00
parent b8579c225c
commit 93037f7642

View File

@ -2045,15 +2045,12 @@ rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) {
* scenario which can make repl_stream_db be -1, that is the instance is * 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. */ * a master, and it have repl_backlog, but server.slaveseldb is -1. */
if (!server.masterhost && server.repl_backlog) { if (!server.masterhost && server.repl_backlog) {
rsi->repl_stream_db = server.slaveseldb; rsi->repl_stream_db = server.slaveseldb == -1 ? 0 : server.slaveseldb;
/* Note that server.slaveseldb may be -1, it means that this master /* Note that when server.slaveseldb is -1, it means that this master
* didn't apply any write commands after a full synchronization, * didn't apply any write commands after a full synchronization.
* so we can leave the currently selected DB set to -1, because the * So we can let repl_stream_db be 0, this allows a restarted slave
* next write command must generate a SELECT statement. This allows * to reload replication ID/offset, it's safe because the next write
* a restarted slave to reload replication ID/offset even the repl_stream_db * command must generate a SELECT statement. */
* 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. */
return rsi; return rsi;
} }