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

Function replicationStartPendingFork

src/replication.cpp:4998–5034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4996}
4997
4998void replicationStartPendingFork(void) {
4999 /* Start a BGSAVE good for replication if we have slaves in
5000 * WAIT_BGSAVE_START state.
5001 *
5002 * In case of diskless replication, we make sure to wait the specified
5003 * number of seconds (according to configuration) so that other slaves
5004 * have the time to arrive before we start streaming. */
5005 if (!hasActiveChildProcessOrBGSave()) {
5006 time_t idle, max_idle = 0;
5007 int slaves_waiting = 0;
5008 int mincapa = -1;
5009 listNode *ln;
5010 listIter li;
5011
5012 listRewind(g_pserver->slaves,&li);
5013 while((ln = listNext(&li))) {
5014 client *replica = (client*)ln->value;
5015 if (replica->replstate == SLAVE_STATE_WAIT_BGSAVE_START) {
5016 idle = g_pserver->unixtime - replica->lastinteraction;
5017 if (idle > max_idle) max_idle = idle;
5018 slaves_waiting++;
5019 mincapa = (mincapa == -1) ? replica->slave_capa :
5020 (mincapa & replica->slave_capa);
5021 }
5022 }
5023
5024 if (slaves_waiting &&
5025 (!g_pserver->repl_diskless_sync ||
5026 max_idle >= g_pserver->repl_diskless_sync_delay))
5027 {
5028 /* Start the BGSAVE. The called function may start a
5029 * BGSAVE with socket target or disk target depending on the
5030 * configuration and slaves capabilities. */
5031 startBgsaveForReplication(mincapa);
5032 }
5033 }
5034}
5035
5036/* Find replica at IP:PORT from replica list */
5037static client *findReplica(char *host, int port) {

Callers 2

replicationCronFunction · 0.85
checkChildrenDoneFunction · 0.85

Calls 4

listRewindFunction · 0.85
listNextFunction · 0.85

Tested by

no test coverage detected