From 785779ee409cf43b3dd018a6cec09c61adbaacb0 Mon Sep 17 00:00:00 2001 From: John Sully Date: Sun, 12 Jul 2020 01:13:22 +0000 Subject: [PATCH] Fix failure to merge databases on active replica sync, due to bad merge with Redis 6 Former-commit-id: cd9514f4c8624932df2ec60ae3c2244899844aa6 --- src/replication.cpp | 6 ++++-- tests/integration/replication-active.tcl | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/replication.cpp b/src/replication.cpp index 768a53f0c..b502cf0e7 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -2069,7 +2069,6 @@ void readSyncBulkPayload(connection *conn) { * * 2. Or when we are done reading from the socket to the RDB file, in * such case we want just to read the RDB file in memory. */ - serverLog(LL_NOTICE, "MASTER <-> REPLICA sync: Flushing old data"); /* We need to stop any AOF rewriting child before flusing and parsing * the RDB, otherwise we'll create a copy-on-write disaster. */ @@ -2089,7 +2088,10 @@ void readSyncBulkPayload(connection *conn) { * (Where disklessLoadMakeBackups left server.db empty) because we * want to execute all the auxiliary logic of emptyDb (Namely, * fire module events) */ - emptyDb(-1,empty_db_flags,replicationEmptyDbCallback); + if (!fUpdate) { + serverLog(LL_NOTICE, "MASTER <-> REPLICA sync: Flushing old data"); + emptyDb(-1,empty_db_flags,replicationEmptyDbCallback); + } /* Before loading the DB into memory we need to delete the readable * handler, otherwise it will get called recursively since diff --git a/tests/integration/replication-active.tcl b/tests/integration/replication-active.tcl index 0fca9a829..6c3c6d674 100644 --- a/tests/integration/replication-active.tcl +++ b/tests/integration/replication-active.tcl @@ -237,3 +237,18 @@ start_server {tags {"active-repl"} overrides {active-replica yes}} { } } } + +start_server {tags {"active-repl"} overrides {active-replica yes}} { + set slave [srv 0 client] + set slave_host [srv 0 host] + set slave_port [srv 0 port] + start_server {tags {"active-repl"} overrides { active-replica yes}} { + r set testkeyB bar + test {Active Replica Merges Database On Sync} { + $slave set testkeyA foo + r replicaof $slave_host $slave_port + after 1000 + assert_equal 2 [r dbsize] + } + } +}