summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhaozhao.zz <zhaozhao.zz@alibaba-inc.com>2017-11-01 17:32:23 +0800
committerantirez <antirez@gmail.com>2017-11-24 11:09:14 +0100
commit9f69e179cf7c7e985855babaf894eb600a54edb1 (patch)
tree3351e02af1f3dd73a93201ab90129e059a5867a6
parent0205dd01e2d0180474c24aceae0a51e6a3862e64 (diff)
downloadredis-9f69e179cf7c7e985855babaf894eb600a54edb1.tar.gz
PSYNC2: safe free backlog when reach the time limit
When we free the backlog, we should use a new replication ID and clear the ID2. Since without backlog we can not increment master_repl_offset even do write commands, that may lead to inconsistency when we try to connect a "slave-before" master (if this master is our slave before, our replid equals the master's replid2). As the master have our history, so we can match the master's replid2 and second_replid_offset, that make partial sync work, but the data is inconsistent.
-rw-r--r--src/replication.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/replication.c b/src/replication.c
index e0b3d910e..fe7b0f739 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -2613,6 +2613,18 @@ void replicationCron(void) {
time_t idle = server.unixtime - server.repl_no_slaves_since;
if (idle > server.repl_backlog_time_limit) {
+ /* When we free the backlog, we always use a new
+ * replication ID and clear the ID2. Since without
+ * backlog we can not increment master_repl_offset
+ * even do write commands, that may lead to inconsistency
+ * when we try to connect a "slave-before" master
+ * (if this master is our slave before, our replid
+ * equals the master's replid2). As the master have our
+ * history, so we can match the master's replid2 and
+ * second_replid_offset, that make partial sync work,
+ * but the data is inconsistent. */
+ changeReplicationId();
+ clearReplicationId2();
freeReplicationBacklog();
serverLog(LL_NOTICE,
"Replication backlog freed after %d seconds "