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

Function launchRdbSaveThread

src/rdb.cpp:1636–1673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1634}
1635
1636int launchRdbSaveThread(pthread_t &child, rdbSaveInfo *rsi)
1637{
1638 if (cserver.fForkBgSave) {
1639 return rdbSaveBackgroundFork(rsi);
1640 } else
1641 {
1642 rdbSaveThreadArgs *args = (rdbSaveThreadArgs*)zcalloc(sizeof(rdbSaveThreadArgs) + ((cserver.dbnum-1)*sizeof(redisDbPersistentDataSnapshot*)), MALLOC_LOCAL);
1643 args = new (args) rdbSaveThreadArgs();
1644 rdbSaveInfo rsiT;
1645 if (rsi == nullptr)
1646 rsi = &rsiT;
1647 args->rsi = *rsi;
1648 memcpy(&args->rsi.repl_id, g_pserver->replid, sizeof(g_pserver->replid));
1649 args->rsi.master_repl_offset = g_pserver->master_repl_offset;
1650
1651 for (int idb = 0; idb < cserver.dbnum; ++idb)
1652 args->rgpdb[idb] = g_pserver->db[idb]->createSnapshot(getMvccTstamp(), false /* fOptional */);
1653
1654 g_pserver->rdbThreadVars.tmpfileNum++;
1655 g_pserver->rdbThreadVars.fRdbThreadCancel = false;
1656 pthread_attr_t tattr;
1657 pthread_attr_init(&tattr);
1658 pthread_attr_setstacksize(&tattr, 1 << 23); // 8 MB
1659 openChildInfoPipe();
1660 if (pthread_create(&child, &tattr, rdbSaveThread, args)) {
1661 pthread_attr_destroy(&tattr);
1662 for (int idb = 0; idb < cserver.dbnum; ++idb)
1663 g_pserver->db[idb]->endSnapshot(args->rgpdb[idb]);
1664 args->~rdbSaveThreadArgs();
1665 zfree(args);
1666 closeChildInfoPipe();
1667 return C_ERR;
1668 }
1669 pthread_attr_destroy(&tattr);
1670 g_pserver->child_type = CHILD_TYPE_RDB;
1671 }
1672 return C_OK;
1673}
1674
1675
1676int rdbSaveBackground(rdbSaveInfo *rsi) {

Callers 1

rdbSaveBackgroundFunction · 0.85

Calls 9

rdbSaveBackgroundForkFunction · 0.85
zcallocFunction · 0.85
getMvccTstampFunction · 0.85
openChildInfoPipeFunction · 0.85
zfreeFunction · 0.85
closeChildInfoPipeFunction · 0.85
endSnapshotMethod · 0.80
pthread_createFunction · 0.50
createSnapshotMethod · 0.45

Tested by

no test coverage detected