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

Function addReplyReplicationBacklog

src/replication.cpp:797–835  ·  view source on GitHub ↗

Feed the replica 'c' with the replication backlog starting from the * specified 'offset' up to the end of the backlog. */

Source from the content-addressed store, hash-verified

795/* Feed the replica 'c' with the replication backlog starting from the
796 * specified 'offset' up to the end of the backlog. */
797long long addReplyReplicationBacklog(client *c, long long offset) {
798 long long skip, len;
799
800 serverLog(LL_DEBUG, "[PSYNC] Replica request offset: %lld", offset);
801
802 if (g_pserver->repl_backlog_histlen == 0) {
803 serverLog(LL_DEBUG, "[PSYNC] Backlog history len is zero");
804 c->repl_curr_off = g_pserver->master_repl_offset;
805 c->repl_end_off = g_pserver->master_repl_offset;
806 return 0;
807 }
808
809 serverLog(LL_DEBUG, "[PSYNC] Backlog size: %lld",
810 g_pserver->repl_backlog_size);
811 serverLog(LL_DEBUG, "[PSYNC] First byte: %lld",
812 g_pserver->repl_backlog_off);
813 serverLog(LL_DEBUG, "[PSYNC] History len: %lld",
814 g_pserver->repl_backlog_histlen);
815 serverLog(LL_DEBUG, "[PSYNC] Current index: %lld",
816 g_pserver->repl_backlog_idx);
817
818 /* Compute the amount of bytes we need to discard. */
819 skip = offset - g_pserver->repl_backlog_off;
820 serverLog(LL_DEBUG, "[PSYNC] Skipping: %lld", skip);
821
822 len = g_pserver->repl_backlog_histlen - skip;
823 serverLog(LL_DEBUG, "[PSYNC] Reply total length: %lld", len);
824
825 /* Set the start and end offsets for the replica so that a future
826 * writeToClient will send the backlog from the given offset to
827 * the current end of the backlog to said replica */
828 c->repl_curr_off = offset - 1;
829 c->repl_end_off = g_pserver->master_repl_offset;
830
831 /* Force the partial sync to be queued */
832 prepareClientToWrite(c);
833
834 return len;
835}
836
837/* Return the offset to provide as reply to the PSYNC command received
838 * from the replica. The returned value is only valid immediately after

Callers 1

Calls 2

serverLogFunction · 0.85
prepareClientToWriteFunction · 0.85

Tested by

no test coverage detected