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
| 4379 | * current offset if no data was lost during the failover. So we use our |
| 4380 | * current replication ID and offset in order to synthesize a cached master. */ |
| 4381 | void replicationCacheMasterUsingMyself(redisMaster *mi) { |
| 4382 | serverLog(LL_NOTICE, |
| 4383 | "Before turning into a replica, using my own master parameters " |
| 4384 | "to synthesize a cached master: I may be able to synchronize with " |
| 4385 | "the new master with just a partial transfer."); |
| 4386 | |
| 4387 | if (mi->cached_master != nullptr) |
| 4388 | { |
| 4389 | // This can happen on first load of the RDB, the master we created in config load is stale |
| 4390 | freeClient(mi->cached_master); |
| 4391 | } |
| 4392 | |
| 4393 | /* This will be used to populate the field g_pserver->master->reploff |
| 4394 | * by replicationCreateMasterClient(). We'll later set the created |
| 4395 | * master as g_pserver->cached_master, so the replica will use such |
| 4396 | * offset for PSYNC. */ |
| 4397 | mi->master_initial_offset = g_pserver->master_repl_offset; |
| 4398 | |
| 4399 | /* The master client we create can be set to any DBID, because |
| 4400 | * the new master will start its replication stream with SELECT. */ |
| 4401 | replicationCreateMasterClient(mi,NULL,-1); |
| 4402 | std::lock_guard<decltype(mi->master->lock)> lock(mi->master->lock); |
| 4403 | |
| 4404 | /* Use our own ID / offset. */ |
| 4405 | memcpy(mi->master->replid, g_pserver->replid, sizeof(g_pserver->replid)); |
| 4406 | |
| 4407 | /* Set as cached master. */ |
| 4408 | unlinkClient(mi->master); |
| 4409 | mi->cached_master = mi->master; |
| 4410 | mi->master = NULL; |
| 4411 | } |
| 4412 | |
| 4413 | /* This function is called when reloading master info from an RDB in Active Replica mode. |
| 4414 | * It creates a cached master client using the info contained in the redisMaster struct. |
no test coverage detected