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

Function removeRDBUsedToSyncReplicas

src/replication.cpp:1812–1854  ·  view source on GitHub ↗

We call this function periodically to remove an RDB file that was * generated because of replication, in an instance that is otherwise * without any persistence. We don't want instances without persistence * to take RDB files around, this violates certain policies in certain * environments. */

Source from the content-addressed store, hash-verified

1810 * to take RDB files around, this violates certain policies in certain
1811 * environments. */
1812void removeRDBUsedToSyncReplicas(void) {
1813 serverAssert(GlobalLocksAcquired());
1814
1815 /* If the feature is disabled, return ASAP but also clear the
1816 * RDBGeneratedByReplication flag in case it was set. Otherwise if the
1817 * feature was enabled, but gets disabled later with CONFIG SET, the
1818 * flag may remain set to one: then next time the feature is re-enabled
1819 * via CONFIG SET we have have it set even if no RDB was generated
1820 * because of replication recently. */
1821 if (!g_pserver->rdb_del_sync_files) {
1822 RDBGeneratedByReplication = 0;
1823 return;
1824 }
1825
1826 if (allPersistenceDisabled() && RDBGeneratedByReplication) {
1827 client *slave;
1828 listNode *ln;
1829 listIter li;
1830
1831 int delrdb = 1;
1832 listRewind(g_pserver->slaves,&li);
1833 while((ln = listNext(&li))) {
1834 slave = (client*)ln->value;
1835 if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START ||
1836 slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END ||
1837 slave->replstate == SLAVE_STATE_SEND_BULK)
1838 {
1839 delrdb = 0;
1840 break; /* No need to check the other replicas. */
1841 }
1842 }
1843 if (delrdb) {
1844 struct stat sb;
1845 if (lstat(g_pserver->rdb_filename,&sb) != -1) {
1846 RDBGeneratedByReplication = 0;
1847 serverLog(LL_NOTICE,
1848 "Removing the RDB file used to feed replicas "
1849 "in a persistence-less instance");
1850 bg_unlink(g_pserver->rdb_filename);
1851 }
1852 }
1853 }
1854}
1855
1856void sendBulkToSlave(connection *conn) {
1857 serverAssert(GlobalLocksAcquired());

Callers 1

replicationCronFunction · 0.85

Calls 6

GlobalLocksAcquiredFunction · 0.85
allPersistenceDisabledFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
serverLogFunction · 0.85
bg_unlinkFunction · 0.85

Tested by

no test coverage detected