MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / shiftReplicationId

Function shiftReplicationId

src/replication.cpp:2287–2299  ·  view source on GitHub ↗

Use the current replication ID / offset as secondary replication * ID, and change the current one in order to start a new history. * This should be used when an instance is switched from replica to master * so that it can serve PSYNC requests performed using the master * replication ID. */

Source from the content-addressed store, hash-verified

2285 * so that it can serve PSYNC requests performed using the master
2286 * replication ID. */
2287void shiftReplicationId(void) {
2288 memcpy(g_pserver->replid2,g_pserver->replid,sizeof(g_pserver->replid));
2289 /* We set the second replid offset to the master offset + 1, since
2290 * the replica will ask for the first byte it has not yet received, so
2291 * we need to add one to the offset: for example if, as a replica, we are
2292 * sure we have the same history as the master for 50 bytes, after we
2293 * are turned into a master, we can accept a PSYNC request with offset
2294 * 51, since the replica asking has the same history up to the 50th
2295 * byte, and is asking for the new bytes starting at offset 51. */
2296 g_pserver->second_replid_offset = g_pserver->master_repl_offset+1;
2297 changeReplicationId();
2298 serverLog(LL_WARNING,"Setting secondary replication ID to %s, valid up to offset: %lld. New replication ID is %s", g_pserver->replid2, g_pserver->second_replid_offset, g_pserver->replid);
2299}
2300
2301/* ----------------------------------- SLAVE -------------------------------- */
2302

Callers 1

replicationUnsetMasterFunction · 0.85

Calls 2

changeReplicationIdFunction · 0.85
serverLogFunction · 0.85

Tested by

no test coverage detected