MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / cancelReplicationHandshake

Function cancelReplicationHandshake

src/replication.cpp:3868–3904  ·  view source on GitHub ↗

This function aborts a non blocking replication attempt if there is one * in progress, by canceling the non-blocking connect attempt or * the initial bulk transfer. * * If there was a replication handshake in progress 1 is returned and * the replication state (g_pserver->repl_state) set to REPL_STATE_CONNECT. * * Otherwise zero is returned and no operation is performed at all. */

Source from the content-addressed store, hash-verified

3866 *
3867 * Otherwise zero is returned and no operation is performed at all. */
3868int cancelReplicationHandshake(redisMaster *mi, int reconnect) {
3869 if (mi->bulkreadBuffer != nullptr) {
3870 sdsfree(mi->bulkreadBuffer);
3871 mi->bulkreadBuffer = nullptr;
3872 }
3873 if (mi->parseState) {
3874 delete mi->parseState;
3875 mi->parseState = nullptr;
3876 }
3877 if (mi->bulkreadBuffer) {
3878 sdsfree(mi->bulkreadBuffer);
3879 mi->bulkreadBuffer = nullptr;
3880 }
3881
3882 if (mi->repl_state == REPL_STATE_TRANSFER) {
3883 replicationAbortSyncTransfer(mi);
3884 mi->repl_state = REPL_STATE_CONNECT;
3885 } else if (mi->repl_state == REPL_STATE_CONNECTING ||
3886 slaveIsInHandshakeState(mi))
3887 {
3888 undoConnectWithMaster(mi);
3889 mi->repl_state = REPL_STATE_CONNECT;
3890 } else {
3891 return 0;
3892 }
3893
3894 if (!reconnect || g_pserver->fActiveReplica)
3895 return 1;
3896
3897 /* try to re-connect without waiting for replicationCron, this is needed
3898 * for the "diskless loading short read" test. */
3899 serverLog(LL_NOTICE,"Reconnecting to MASTER %s:%d after failure",
3900 mi->masterhost, mi->masterport);
3901 connectWithMaster(mi);
3902
3903 return 1;
3904}
3905
3906void disconnectMaster(redisMaster *mi)
3907{

Callers 5

readSnapshotBulkPayloadFunction · 0.85
readSyncBulkPayloadRdbFunction · 0.85
replicationAddMasterFunction · 0.85
replicationUnsetMasterFunction · 0.85
replicationCronFunction · 0.85

Calls 6

sdsfreeFunction · 0.85
slaveIsInHandshakeStateFunction · 0.85
undoConnectWithMasterFunction · 0.85
serverLogFunction · 0.85
connectWithMasterFunction · 0.85

Tested by

no test coverage detected