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

Function rewriteAppendOnlyFileRio

src/aof.cpp:1550–1640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1548}
1549
1550int rewriteAppendOnlyFileRio(rio *aof) {
1551 size_t processed = 0;
1552 int j;
1553 long key_count = 0;
1554 long long updated_time = 0;
1555
1556 for (j = 0; j < cserver.dbnum; j++) {
1557 char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n";
1558 redisDb *db = g_pserver->db[j];
1559 if (db->size() == 0) continue;
1560
1561 /* SELECT the new DB */
1562 if (rioWrite(aof,selectcmd,sizeof(selectcmd)-1) == 0) goto werr;
1563 if (rioWriteBulkLongLong(aof,j) == 0) goto werr;
1564
1565 /* Iterate this DB writing every entry */
1566 bool fComplete = db->iterate([&](const char *keystr, robj *o)->bool{
1567 redisObjectStack key;
1568 initStaticStringObject(key,(sds)keystr);
1569
1570 /* Save the key and associated value */
1571 if (o->type == OBJ_STRING) {
1572 /* Emit a SET command */
1573 char cmd[]="*3\r\n$3\r\nSET\r\n";
1574 if (rioWrite(aof,cmd,sizeof(cmd)-1) == 0) return false;
1575 /* Key and value */
1576 if (rioWriteBulkObject(aof,&key) == 0) return false;
1577 if (rioWriteBulkObject(aof,o) == 0) return false;
1578 } else if (o->type == OBJ_LIST) {
1579 if (rewriteListObject(aof,&key,o) == 0) return false;
1580 } else if (o->type == OBJ_SET) {
1581 if (rewriteSetObject(aof,&key,o) == 0) return false;
1582 } else if (o->type == OBJ_ZSET) {
1583 if (rewriteSortedSetObject(aof,&key,o) == 0) return false;
1584 } else if (o->type == OBJ_HASH) {
1585 if (rewriteHashObject(aof,&key,o) == 0) return false;
1586 } else if (o->type == OBJ_STREAM) {
1587 if (rewriteStreamObject(aof,&key,o) == 0) return false;
1588 } else if (o->type == OBJ_MODULE) {
1589 if (rewriteModuleObject(aof,&key,o) == 0) return false;
1590 } else {
1591 serverPanic("Unknown object type");
1592 }
1593 /* Save the expire time */
1594 if (o->FExpires()) {
1595 expireEntry *pexpire = &o->expire;
1596 for (auto &subExpire : *pexpire) {
1597 if (subExpire.subkey() == nullptr)
1598 {
1599 char cmd[]="*3\r\n$9\r\nPEXPIREAT\r\n";
1600 if (rioWrite(aof,cmd,sizeof(cmd)-1) == 0) return false;
1601 if (rioWriteBulkObject(aof,&key) == 0) return false;
1602 }
1603 else
1604 {
1605 char cmd[]="*4\r\n$12\r\nPEXPIREMEMBERAT\r\n";
1606 if (rioWrite(aof,cmd,sizeof(cmd)-1) == 0) return false;
1607 if (rioWriteBulkObject(aof,&key) == 0) return false;

Callers 1

rewriteAppendOnlyFileFunction · 0.85

Calls 15

rioWriteFunction · 0.85
rioWriteBulkLongLongFunction · 0.85
rioWriteBulkObjectFunction · 0.85
rewriteListObjectFunction · 0.85
rewriteSetObjectFunction · 0.85
rewriteSortedSetObjectFunction · 0.85
rewriteHashObjectFunction · 0.85
rewriteStreamObjectFunction · 0.85
rewriteModuleObjectFunction · 0.85
sdslenFunction · 0.85
aofReadDiffFromParentFunction · 0.85
sendChildInfoFunction · 0.85

Tested by

no test coverage detected