summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhaozhao.zz <zhaozhao.zz@alibaba-inc.com>2017-11-04 23:05:00 +0800
committerzhaozhao.zz <zhaozhao.zz@alibaba-inc.com>2017-11-22 12:11:26 +0800
commitea2e51c630f972b23d3557f6369b13d983c12f17 (patch)
treeb6fe5d993752870f9e162385e41675853058c617
parent93037f764209e86f3fcb240a642334fd67552935 (diff)
downloadredis-ea2e51c630f972b23d3557f6369b13d983c12f17.tar.gz
PSYNC2: persist cached_master's dbid inside the RDB
-rw-r--r--src/rdb.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/rdb.c b/src/rdb.c
index 386b6a78f..a7334449e 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -2054,11 +2054,25 @@ rdbSaveInfo *rdbPopulateSaveInfo(rdbSaveInfo *rsi) {
return rsi;
}
- /* If the instance is a slave we need a connected master in order to
- * fetch the currently selected DB. */
+ /* If the instance is a slave we need a connected master
+ * in order to fetch the currently selected DB. */
if (server.master) {
rsi->repl_stream_db = server.master->db->id;
return rsi;
}
+ /* It is useful to persist cached_master's db id inside RDB file.
+ * When a slave lost master's connection, server.master will be
+ * cached as server.cached_master, after that a slave can not
+ * increment the master_repl_offset because slave only apply data
+ * from connected master, so the cached_master can hold right
+ * replication info. But please note that this action is safe
+ * only after we fix the free backlog problem, because when a master
+ * turn to be a slave, it will use itself as the server.cached_master,
+ * that is dangerous if we didn't use a new replication ID after
+ * free backlog. */
+ if (server.cached_master) {
+ rsi->repl_stream_db = server.cached_master->db->id;
+ return rsi;
+ }
return NULL;
}