From da309f7045407c34f7dc4cf2350ecab7fc7b6c32 Mon Sep 17 00:00:00 2001 From: John Sully Date: Sun, 31 May 2020 16:03:23 -0400 Subject: [PATCH] Active replicas referencing eachother should connect one at a time Former-commit-id: c0c033a0c175eebdf2173e6e4e59e792d2fe4285 --- src/replication.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/replication.cpp b/src/replication.cpp index 103529eaf..2f8a74837 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -1121,6 +1121,25 @@ void processReplconfUuid(client *c, robj *arg) if (uuid_parse(remoteUUID, c->uuid) != 0) goto LError; + listIter liMi; + listNode *lnMi; + listRewind(g_pserver->masters, &liMi); + + // Enforce a fair ordering for connection, if they attempt to connect before us close them out + // This must be consistent so that both make the same decision of who should proceed first + while ((lnMi = listNext(&liMi))) { + redisMaster *mi = (redisMaster*)listNodeValue(lnMi); + if (mi->repl_state == REPL_STATE_CONNECTED) + continue; + if (FSameUuidNoNil(mi->master_uuid, c->uuid)) { + // Decide based on UUID so both clients make the same decision of which host loses + // otherwise we may entere a loop where neither client can proceed + if (memcmp(mi->master_uuid, c->uuid, UUID_BINARY_LEN) < 0) { + freeClientAsync(c); + } + } + } + char szServerUUID[36 + 2]; // 1 for the '+', another for '\0' szServerUUID[0] = '+'; uuid_unparse(cserver.uuid, szServerUUID+1);