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

Function rdbSaveBackgroundFork

src/rdb.cpp:1598–1634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1596}
1597
1598int rdbSaveBackgroundFork(rdbSaveInfo *rsi) {
1599 pid_t childpid;
1600
1601 if (hasActiveChildProcess() || g_pserver->rdb_child_pid != -1) return C_ERR;
1602 serverAssert(g_pserver->rdb_child_pid != 10000);
1603
1604 g_pserver->dirty_before_bgsave = g_pserver->dirty;
1605 g_pserver->lastbgsave_try = time(NULL);
1606
1607 if ((childpid = redisFork(CHILD_TYPE_RDB)) == 0) {
1608 int retval;
1609
1610 /* Child */
1611 g_pserver->rdb_child_pid = 10000;
1612 redisSetProcTitle("keydb-rdb-bgsave");
1613 redisSetCpuAffinity(g_pserver->bgsave_cpulist);
1614 retval = rdbSave(nullptr, rsi);
1615 if (retval == C_OK) {
1616 sendChildCowInfo(CHILD_INFO_TYPE_RDB_COW_SIZE, "RDB");
1617 }
1618 exitFromChild((retval == C_OK) ? 0 : 1);
1619 } else {
1620 /* Parent */
1621 if (childpid == -1) {
1622 g_pserver->lastbgsave_status = C_ERR;
1623 serverLog(LL_WARNING,"Can't save in background: fork: %s",
1624 strerror(errno));
1625 return C_ERR;
1626 }
1627 serverLog(LL_NOTICE,"Background saving started by pid %d",childpid);
1628 g_pserver->rdb_save_time_start = time(NULL);
1629 g_pserver->rdb_child_type = RDB_CHILD_TYPE_DISK;
1630 updateDictResizePolicy();
1631 return C_OK;
1632 }
1633 return C_OK; /* unreached */
1634}
1635
1636int launchRdbSaveThread(pthread_t &child, rdbSaveInfo *rsi)
1637{

Callers 1

launchRdbSaveThreadFunction · 0.85

Calls 9

hasActiveChildProcessFunction · 0.85
redisForkFunction · 0.85
redisSetProcTitleFunction · 0.85
redisSetCpuAffinityFunction · 0.85
rdbSaveFunction · 0.85
sendChildCowInfoFunction · 0.85
exitFromChildFunction · 0.85
serverLogFunction · 0.85
updateDictResizePolicyFunction · 0.85

Tested by

no test coverage detected