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
| 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. */ |
| 2949 | void 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. */ |
no test coverage detected