From 189a12afb4df2986d4671cdebae3c96c4f0945c2 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 19 Apr 2017 14:02:52 +0200 Subject: [PATCH] PSYNC2: discard pending transactions from cached master. During the review of the fix for #3899, @yangsiran identified an implementation bug: given that the offset is now relative to the applied part of the replication log, when we cache a master, the successive PSYNC2 request will be made in order to *include* the transaction that was not completely processed. This means that we need to discard any pending transaction from our replication buffer: it will be re-executed. --- src/replication.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/replication.c b/src/replication.c index 91ede828d..1828eb8bf 100644 --- a/src/replication.c +++ b/src/replication.c @@ -2120,10 +2120,12 @@ void replicationCacheMaster(client *c) { unlinkClient(c); /* Fix the master specific fields: we want to discard to non processed - * query buffers and non processed offsets. */ + * query buffers and non processed offsets, including pending + * transactions. */ sdsclear(server.master->querybuf); sdsclear(server.master->pending_querybuf); server.master->read_reploff = server.master->reploff; + if (c->flags & CLIENT_MULTI) discardTransaction(c); /* Save the master. Server.master will be set to null later by * replicationHandleMasterDisconnection(). */