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

Function replicationCacheMasterUsingMyself

app/redis-6.2.6/src/replication.c:2949–2972  ·  view source on GitHub ↗

This function is called when a master is turend into a slave, in order to * create from scratch a cached master for the new client, that will allow * to PSYNC with the slave that was promoted as the new master after a * failover. * * Assuming this instance was previously the master instance of the new master, * the new master will accept its replication ID, and potentiall also the * current

Source from the content-addressed store, hash-verified

2947 * current offset if no data was lost during the failover. So we use our
2948 * current replication ID and offset in order to synthesize a cached master. */
2949void replicationCacheMasterUsingMyself(void) {
2950 serverLog(LL_NOTICE,
2951 "Before turning into a replica, using my own master parameters "
2952 "to synthesize a cached master: I may be able to synchronize with "
2953 "the new master with just a partial transfer.");
2954
2955 /* This will be used to populate the field server.master->reploff
2956 * by replicationCreateMasterClient(). We'll later set the created
2957 * master as server.cached_master, so the replica will use such
2958 * offset for PSYNC. */
2959 server.master_initial_offset = server.master_repl_offset;
2960
2961 /* The master client we create can be set to any DBID, because
2962 * the new master will start its replication stream with SELECT. */
2963 replicationCreateMasterClient(NULL,-1);
2964
2965 /* Use our own ID / offset. */
2966 memcpy(server.master->replid, server.replid, sizeof(server.replid));
2967
2968 /* Set as cached master. */
2969 unlinkClient(server.master);
2970 server.cached_master = server.master;
2971 server.master = NULL;
2972}
2973
2974/* Free a cached master, called when there are no longer the conditions for
2975 * a partial resync on reconnection. */

Callers 2

replicationSetMasterFunction · 0.85
loadDataFromDiskFunction · 0.85

Calls 3

unlinkClientFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected