This function is called when the replica lose the connection with the * master into an unexpected way. */
| 4085 | /* This function is called when the replica lose the connection with the |
| 4086 | * master into an unexpected way. */ |
| 4087 | void replicationHandleMasterDisconnection(redisMaster *mi) { |
| 4088 | if (mi != nullptr) |
| 4089 | { |
| 4090 | /* Fire the master link modules event. */ |
| 4091 | if (mi->repl_state == REPL_STATE_CONNECTED) |
| 4092 | moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE, |
| 4093 | REDISMODULE_SUBEVENT_MASTER_LINK_DOWN, |
| 4094 | NULL); |
| 4095 | if (mi->master && mi->master->repl_down_since) { |
| 4096 | mi->repl_down_since = mi->master->repl_down_since; |
| 4097 | } |
| 4098 | else { |
| 4099 | mi->repl_down_since = g_pserver->unixtime; |
| 4100 | } |
| 4101 | mi->master = NULL; |
| 4102 | mi->repl_state = REPL_STATE_CONNECT; |
| 4103 | /* We lost connection with our master, don't disconnect slaves yet, |
| 4104 | * maybe we'll be able to PSYNC with our master later. We'll disconnect |
| 4105 | * the slaves only if we'll have to do a full resync with our master. */ |
| 4106 | |
| 4107 | /* Try to re-connect immediately rather than wait for replicationCron |
| 4108 | * waiting 1 second may risk backlog being recycled. */ |
| 4109 | if (mi->masterhost && !g_pserver->fActiveReplica) { |
| 4110 | serverLog(LL_NOTICE,"Reconnecting to MASTER %s:%d", |
| 4111 | mi->masterhost, mi->masterport); |
| 4112 | connectWithMaster(mi); |
| 4113 | } |
| 4114 | |
| 4115 | saveMasterStatusToStorage(false); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | void replicaofCommand(client *c) { |
| 4120 | /* SLAVEOF is not allowed in cluster mode as replication is automatically |
no test coverage detected