Function called at startup to load RDB or AOF file in memory. */
| 7036 | |
| 7037 | /* Function called at startup to load RDB or AOF file in memory. */ |
| 7038 | void loadDataFromDisk(void) { |
| 7039 | long long start = ustime(); |
| 7040 | |
| 7041 | if (g_pserver->m_pstorageFactory) |
| 7042 | { |
| 7043 | for (int idb = 0; idb < cserver.dbnum; ++idb) |
| 7044 | { |
| 7045 | if (g_pserver->db[idb]->size() > 0) |
| 7046 | { |
| 7047 | serverLog(LL_NOTICE, "Not loading the RDB because a storage provider is set and the database is not empty"); |
| 7048 | return; |
| 7049 | } |
| 7050 | } |
| 7051 | serverLog(LL_NOTICE, "Loading the RDB even though we have a storage provider because the database is empty"); |
| 7052 | } |
| 7053 | |
| 7054 | serverTL->gcEpoch = g_pserver->garbageCollector.startEpoch(); |
| 7055 | if (g_pserver->aof_state == AOF_ON) { |
| 7056 | if (loadAppendOnlyFile(g_pserver->aof_filename) == C_OK) |
| 7057 | serverLog(LL_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000); |
| 7058 | } else if (g_pserver->rdb_filename != NULL || g_pserver->rdb_s3bucketpath != NULL) { |
| 7059 | rdbSaveInfo rsi; |
| 7060 | rsi.fForceSetKey = false; |
| 7061 | errno = 0; /* Prevent a stale value from affecting error checking */ |
| 7062 | if (rdbLoad(&rsi,RDBFLAGS_NONE) == C_OK) { |
| 7063 | serverLog(LL_NOTICE,"DB loaded from disk: %.3f seconds", |
| 7064 | (float)(ustime()-start)/1000000); |
| 7065 | |
| 7066 | /* Restore the replication ID / offset from the RDB file. */ |
| 7067 | if ((listLength(g_pserver->masters) || |
| 7068 | (g_pserver->cluster_enabled && |
| 7069 | nodeIsSlave(g_pserver->cluster->myself))) && |
| 7070 | rsi.repl_id_is_set && |
| 7071 | rsi.repl_offset != -1 && |
| 7072 | /* Note that older implementations may save a repl_stream_db |
| 7073 | * of -1 inside the RDB file in a wrong way, see more |
| 7074 | * information in function rdbPopulateSaveInfo. */ |
| 7075 | rsi.repl_stream_db != -1) |
| 7076 | { |
| 7077 | memcpy(g_pserver->replid,rsi.repl_id,sizeof(g_pserver->replid)); |
| 7078 | g_pserver->master_repl_offset = rsi.repl_offset; |
| 7079 | if (g_pserver->repl_batch_offStart >= 0) |
| 7080 | g_pserver->repl_batch_offStart = g_pserver->master_repl_offset; |
| 7081 | } |
| 7082 | updateActiveReplicaMastersFromRsi(&rsi); |
| 7083 | if (!g_pserver->fActiveReplica && listLength(g_pserver->masters)) { |
| 7084 | redisMaster *mi = (redisMaster*)listNodeValue(listFirst(g_pserver->masters)); |
| 7085 | /* If we are a replica, create a cached master from this |
| 7086 | * information, in order to allow partial resynchronizations |
| 7087 | * with masters. */ |
| 7088 | replicationCacheMasterUsingMyself(mi); |
| 7089 | selectDb(mi->cached_master,rsi.repl_stream_db); |
| 7090 | } |
| 7091 | } else if (errno != ENOENT) { |
| 7092 | serverLog(LL_WARNING,"Fatal error loading the DB: %s. Exiting.",strerror(errno)); |
| 7093 | exit(1); |
| 7094 | } |
| 7095 | } |
no test coverage detected