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

Function rdbLoadRio

app/redis-6.2.6/src/rdb.c:2423–2745  ·  view source on GitHub ↗

Load an RDB file from the rio stream 'rdb'. On success C_OK is returned, * otherwise C_ERR is returned and 'errno' is set accordingly. */

Source from the content-addressed store, hash-verified

2421/* Load an RDB file from the rio stream 'rdb'. On success C_OK is returned,
2422 * otherwise C_ERR is returned and 'errno' is set accordingly. */
2423int rdbLoadRio(rio *rdb, int rdbflags, rdbSaveInfo *rsi) {
2424 uint64_t dbid;
2425 int type, rdbver;
2426 redisDb *db = server.db+0;
2427 char buf[1024];
2428 int error;
2429 long long empty_keys_skipped = 0, expired_keys_skipped = 0, keys_loaded = 0;
2430
2431 rdb->update_cksum = rdbLoadProgressCallback;
2432 rdb->max_processing_chunk = server.loading_process_events_interval_bytes;
2433 if (rioRead(rdb,buf,9) == 0) goto eoferr;
2434 buf[9] = '\0';
2435 if (memcmp(buf,"REDIS",5) != 0) {
2436 serverLog(LL_WARNING,"Wrong signature trying to load DB from file");
2437 errno = EINVAL;
2438 return C_ERR;
2439 }
2440 rdbver = atoi(buf+5);
2441 if (rdbver < 1 || rdbver > RDB_VERSION) {
2442 serverLog(LL_WARNING,"Can't handle RDB format version %d",rdbver);
2443 errno = EINVAL;
2444 return C_ERR;
2445 }
2446
2447 /* Key-specific attributes, set by opcodes before the key type. */
2448 long long lru_idle = -1, lfu_freq = -1, expiretime = -1, now = mstime();
2449 long long lru_clock = LRU_CLOCK();
2450
2451 while(1) {
2452 sds key;
2453 robj *val;
2454
2455 /* Read type. */
2456 if ((type = rdbLoadType(rdb)) == -1) goto eoferr;
2457
2458 /* Handle special types. */
2459 if (type == RDB_OPCODE_EXPIRETIME) {
2460 /* EXPIRETIME: load an expire associated with the next key
2461 * to load. Note that after loading an expire we need to
2462 * load the actual type, and continue. */
2463 expiretime = rdbLoadTime(rdb);
2464 expiretime *= 1000;
2465 if (rioGetReadError(rdb)) goto eoferr;
2466 continue; /* Read next opcode. */
2467 } else if (type == RDB_OPCODE_EXPIRETIME_MS) {
2468 /* EXPIRETIME_MS: milliseconds precision expire times introduced
2469 * with RDB v3. Like EXPIRETIME but no with more precision. */
2470 expiretime = rdbLoadMillisecondTime(rdb,rdbver);
2471 if (rioGetReadError(rdb)) goto eoferr;
2472 continue; /* Read next opcode. */
2473 } else if (type == RDB_OPCODE_FREQ) {
2474 /* FREQ: LFU frequency. */
2475 uint8_t byte;
2476 if (rioRead(rdb,&byte,1) == 0) goto eoferr;
2477 lfu_freq = byte;
2478 continue; /* Read next opcode. */
2479 } else if (type == RDB_OPCODE_IDLE) {
2480 /* IDLE: LRU idle time. */

Callers 3

readSyncBulkPayloadFunction · 0.85
rdbLoadFunction · 0.85
loadAppendOnlyFileFunction · 0.85

Calls 15

rioReadFunction · 0.85
LRU_CLOCKFunction · 0.85
rdbLoadTypeFunction · 0.85
rdbLoadTimeFunction · 0.85
rioGetReadErrorFunction · 0.85
rdbLoadMillisecondTimeFunction · 0.85
rdbLoadLenFunction · 0.85
rdbLoadStringObjectFunction · 0.85
strcasecmpFunction · 0.85
sdslenFunction · 0.85
luaCreateFunctionFunction · 0.85
strtolFunction · 0.85

Tested by

no test coverage detected