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. */
| 3093 | /* Load an RDB file from the rio stream 'rdb'. On success C_OK is returned, |
| 3094 | * otherwise C_ERR is returned and 'errno' is set accordingly. */ |
| 3095 | int rdbLoadRio(rio *rdb, int rdbflags, rdbSaveInfo *rsi) { |
| 3096 | uint64_t dbid = 0; |
| 3097 | int type, rdbver; |
| 3098 | redisDb *dbCur = g_pserver->db[dbid]; |
| 3099 | char buf[1024]; |
| 3100 | /* Key-specific attributes, set by opcodes before the key type. */ |
| 3101 | long long lru_idle = -1, lfu_freq = -1, expiretime = INVALID_EXPIRE, now; |
| 3102 | long long lru_clock = 0; |
| 3103 | unsigned long long ckeysLoaded = 0; |
| 3104 | uint64_t mvcc_tstamp = OBJ_MVCC_INVALID; |
| 3105 | now = mstime(); |
| 3106 | rdbAsyncWorkThread wqueue(rsi, rdbflags, now); |
| 3107 | robj *subexpireKey = nullptr; |
| 3108 | sds key = nullptr; |
| 3109 | bool fLastKeyExpired = false; |
| 3110 | int error; |
| 3111 | long long empty_keys_skipped = 0, expired_keys_skipped = 0, keys_loaded = 0; |
| 3112 | std::unique_ptr<rdbInsertJob> spjob; |
| 3113 | |
| 3114 | // If we're tracking changes we need to reset this |
| 3115 | std::vector<bool> fTracking(cserver.dbnum); |
| 3116 | // We don't want to track here because processChangesAsync is outside the normal scope handling |
| 3117 | for (int idb = 0; idb < cserver.dbnum; ++idb) { |
| 3118 | if ((fTracking[idb] = g_pserver->db[idb]->FTrackingChanges())) |
| 3119 | if (g_pserver->db[idb]->processChanges(false)) |
| 3120 | g_pserver->db[idb]->commitChanges(); |
| 3121 | } |
| 3122 | |
| 3123 | rdb->update_cksum = rdbLoadProgressCallback; |
| 3124 | rdb->chksum_arg = &wqueue; |
| 3125 | rdb->max_processing_chunk = g_pserver->loading_process_events_interval_bytes; |
| 3126 | if (rioRead(rdb,buf,9) == 0) goto eoferr; |
| 3127 | buf[9] = '\0'; |
| 3128 | if (memcmp(buf,"REDIS",5) != 0) { |
| 3129 | serverLog(LL_WARNING,"Wrong signature trying to load DB from file"); |
| 3130 | errno = EINVAL; |
| 3131 | return C_ERR; |
| 3132 | } |
| 3133 | rdbver = atoi(buf+5); |
| 3134 | if (rdbver < 1 || rdbver > RDB_VERSION) { |
| 3135 | serverLog(LL_WARNING,"Can't handle RDB format version %d",rdbver); |
| 3136 | errno = EINVAL; |
| 3137 | return C_ERR; |
| 3138 | } |
| 3139 | |
| 3140 | lru_clock = LRU_CLOCK(); |
| 3141 | if (g_pserver->multithread_load_enabled) |
| 3142 | wqueue.start(); |
| 3143 | |
| 3144 | while(1) { |
| 3145 | robj *val; |
| 3146 | |
| 3147 | /* Read type. */ |
| 3148 | if ((type = rdbLoadType(rdb)) == -1) goto eoferr; |
| 3149 | |
| 3150 | /* Handle special types. */ |
| 3151 | if (type == RDB_OPCODE_EXPIRETIME) { |
| 3152 | /* EXPIRETIME: load an expire associated with the next key |
no test coverage detected