MCPcopy Create free account
hub / github.com/F-Stack/f-stack / shiftReplicationId

Function shiftReplicationId

app/redis-6.2.6/src/replication.c:1403–1415  ·  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 slave to master * so that it can serve PSYNC requests performed using the master * replication ID. */

Source from the content-addressed store, hash-verified

1401 * so that it can serve PSYNC requests performed using the master
1402 * replication ID. */
1403void shiftReplicationId(void) {
1404 memcpy(server.replid2,server.replid,sizeof(server.replid));
1405 /* We set the second replid offset to the master offset + 1, since
1406 * the slave will ask for the first byte it has not yet received, so
1407 * we need to add one to the offset: for example if, as a slave, we are
1408 * sure we have the same history as the master for 50 bytes, after we
1409 * are turned into a master, we can accept a PSYNC request with offset
1410 * 51, since the slave asking has the same history up to the 50th
1411 * byte, and is asking for the new bytes starting at offset 51. */
1412 server.second_replid_offset = server.master_repl_offset+1;
1413 changeReplicationId();
1414 serverLog(LL_WARNING,"Setting secondary replication ID to %s, valid up to offset: %lld. New replication ID is %s", server.replid2, server.second_replid_offset, server.replid);
1415}
1416
1417/* ----------------------------------- SLAVE -------------------------------- */
1418

Callers 1

replicationUnsetMasterFunction · 0.85

Calls 2

changeReplicationIdFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected