MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rewriteAppendOnlyFileRio

Function rewriteAppendOnlyFileRio

app/redis-6.2.6/src/aof.c:1451–1537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1449}
1450
1451int rewriteAppendOnlyFileRio(rio *aof) {
1452 dictIterator *di = NULL;
1453 dictEntry *de;
1454 size_t processed = 0;
1455 int j;
1456 long key_count = 0;
1457 long long updated_time = 0;
1458
1459 for (j = 0; j < server.dbnum; j++) {
1460 char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n";
1461 redisDb *db = server.db+j;
1462 dict *d = db->dict;
1463 if (dictSize(d) == 0) continue;
1464 di = dictGetSafeIterator(d);
1465
1466 /* SELECT the new DB */
1467 if (rioWrite(aof,selectcmd,sizeof(selectcmd)-1) == 0) goto werr;
1468 if (rioWriteBulkLongLong(aof,j) == 0) goto werr;
1469
1470 /* Iterate this DB writing every entry */
1471 while((de = dictNext(di)) != NULL) {
1472 sds keystr;
1473 robj key, *o;
1474 long long expiretime;
1475
1476 keystr = dictGetKey(de);
1477 o = dictGetVal(de);
1478 initStaticStringObject(key,keystr);
1479
1480 expiretime = getExpire(db,&key);
1481
1482 /* Save the key and associated value */
1483 if (o->type == OBJ_STRING) {
1484 /* Emit a SET command */
1485 char cmd[]="*3\r\n$3\r\nSET\r\n";
1486 if (rioWrite(aof,cmd,sizeof(cmd)-1) == 0) goto werr;
1487 /* Key and value */
1488 if (rioWriteBulkObject(aof,&key) == 0) goto werr;
1489 if (rioWriteBulkObject(aof,o) == 0) goto werr;
1490 } else if (o->type == OBJ_LIST) {
1491 if (rewriteListObject(aof,&key,o) == 0) goto werr;
1492 } else if (o->type == OBJ_SET) {
1493 if (rewriteSetObject(aof,&key,o) == 0) goto werr;
1494 } else if (o->type == OBJ_ZSET) {
1495 if (rewriteSortedSetObject(aof,&key,o) == 0) goto werr;
1496 } else if (o->type == OBJ_HASH) {
1497 if (rewriteHashObject(aof,&key,o) == 0) goto werr;
1498 } else if (o->type == OBJ_STREAM) {
1499 if (rewriteStreamObject(aof,&key,o) == 0) goto werr;
1500 } else if (o->type == OBJ_MODULE) {
1501 if (rewriteModuleObject(aof,&key,o) == 0) goto werr;
1502 } else {
1503 serverPanic("Unknown object type");
1504 }
1505 /* Save the expire time */
1506 if (expiretime != -1) {
1507 char cmd[]="*3\r\n$9\r\nPEXPIREAT\r\n";
1508 if (rioWrite(aof,cmd,sizeof(cmd)-1) == 0) goto werr;

Callers 1

rewriteAppendOnlyFileFunction · 0.85

Calls 15

dictGetSafeIteratorFunction · 0.85
rioWriteFunction · 0.85
rioWriteBulkLongLongFunction · 0.85
getExpireFunction · 0.85
rioWriteBulkObjectFunction · 0.85
rewriteListObjectFunction · 0.85
rewriteSetObjectFunction · 0.85
rewriteSortedSetObjectFunction · 0.85
rewriteHashObjectFunction · 0.85
rewriteStreamObjectFunction · 0.85
rewriteModuleObjectFunction · 0.85
aofReadDiffFromParentFunction · 0.85

Tested by

no test coverage detected