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

Function replicationSetupSlaveForFullResync

src/replication.cpp:861–887  ·  view source on GitHub ↗

Send a FULLRESYNC reply in the specific case of a full resynchronization, * as a side effect setup the replica for a full sync in different ways: * * 1) Remember, into the replica client structure, the replication offset * we sent here, so that if new slaves will later attach to the same * background RDB saving process (by duplicating this client output * buffer), we can get the rig

Source from the content-addressed store, hash-verified

859 * BGSAVE for replication was started, or when there is one already in
860 * progress that we attached our replica to. */
861int replicationSetupSlaveForFullResync(client *replica, long long offset) {
862 char buf[128];
863 int buflen;
864
865 replica->psync_initial_offset = offset;
866 replica->replstate = SLAVE_STATE_WAIT_BGSAVE_END;
867
868 replica->repl_curr_off = offset;
869 replica->repl_end_off = g_pserver->master_repl_offset;
870
871 /* We are going to accumulate the incremental changes for this
872 * replica as well. Set replicaseldb to -1 in order to force to re-emit
873 * a SELECT statement in the replication stream. */
874 g_pserver->replicaseldb = -1;
875
876 /* Don't send this reply to slaves that approached us with
877 * the old SYNC command. */
878 if (!(replica->flags & CLIENT_PRE_PSYNC)) {
879 buflen = snprintf(buf,sizeof(buf),"+FULLRESYNC %s %lld\r\n",
880 g_pserver->replid,offset);
881 if (connWrite(replica->conn,buf,buflen) != buflen) {
882 freeClientAsync(replica);
883 return C_ERR;
884 }
885 }
886 return C_OK;
887}
888
889/* This function handles the PSYNC command from the point of view of a
890 * master receiving a request for partial resynchronization.

Callers 4

rdbSaveToSlavesSocketsFunction · 0.85
addReplicaMethod · 0.85
syncCommandFunction · 0.85

Calls 2

connWriteFunction · 0.85
freeClientAsyncFunction · 0.85

Tested by

no test coverage detected