summaryrefslogtreecommitdiff
path: root/src/rdb.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-01-07 15:25:58 +0100
committerantirez <antirez@gmail.com>2015-01-08 09:52:51 +0100
commit1a30e7ded14f4cb2ea39e05d1b1e1fd0b4d20ad6 (patch)
treeae7fdf79b93fe7a26aeff30ca28c7ccc93667438 /src/rdb.c
parente8614a1a77d2989f7be3cb7b24cd88b01f14f17e (diff)
downloadredis-1a30e7ded14f4cb2ea39e05d1b1e1fd0b4d20ad6.tar.gz
rdbLoad() refactoring to make it simpler to follow.
Diffstat (limited to 'src/rdb.c')
-rw-r--r--src/rdb.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/rdb.c b/src/rdb.c
index 3e41d4044..cda4c8921 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -1223,7 +1223,12 @@ int rdbLoad(char *filename) {
/* Read type. */
if ((type = rdbLoadType(&rdb)) == -1) goto eoferr;
+
+ /* Handle special types. */
if (type == REDIS_RDB_OPCODE_EXPIRETIME) {
+ /* EXPIRETIME: load an expire associated with the next key
+ * to load. Note that after loading an expire we need to
+ * load the actual type, and continue. */
if ((expiretime = rdbLoadTime(&rdb)) == -1) goto eoferr;
/* We read the time so we need to read the object type again. */
if ((type = rdbLoadType(&rdb)) == -1) goto eoferr;
@@ -1231,27 +1236,30 @@ int rdbLoad(char *filename) {
* into milliseconds. */
expiretime *= 1000;
} else if (type == REDIS_RDB_OPCODE_EXPIRETIME_MS) {
- /* Milliseconds precision expire times introduced with RDB
- * version 3. */
+ /* EXPIRETIME_MS: milliseconds precision expire times introduced
+ * with RDB v3. Like EXPIRETIME but no with more precision. */
if ((expiretime = rdbLoadMillisecondTime(&rdb)) == -1) goto eoferr;
/* We read the time so we need to read the object type again. */
if ((type = rdbLoadType(&rdb)) == -1) goto eoferr;
- }
-
- if (type == REDIS_RDB_OPCODE_EOF)
+ } else if (type == REDIS_RDB_OPCODE_EOF) {
+ /* EOF: End of file, exit the main loop. */
break;
-
- /* Handle special opcodes: SELECTDB, RESIZEDB, AUX. */
- if (type == REDIS_RDB_OPCODE_SELECTDB) {
+ } else if (type == REDIS_RDB_OPCODE_SELECTDB) {
+ /* SELECTDB: Select the specified database. */
if ((dbid = rdbLoadLen(&rdb,NULL)) == REDIS_RDB_LENERR)
goto eoferr;
if (dbid >= (unsigned)server.dbnum) {
- redisLog(REDIS_WARNING,"FATAL: Data file was created with a Redis server configured to handle more than %d databases. Exiting\n", server.dbnum);
+ redisLog(REDIS_WARNING,
+ "FATAL: Data file was created with a Redis "
+ "server configured to handle more than %d "
+ "databases. Exiting\n", server.dbnum);
exit(1);
}
db = server.db+dbid;
- continue;
+ continue; /* Read type again. */
} else if (type == REDIS_RDB_OPCODE_RESIZEDB) {
+ /* RESIZEDB: Hint about the size of the keys in the currently
+ * selected data base, in order to avoid useless rehashing. */
uint32_t db_size, expires_size;
if ((db_size = rdbLoadLen(&rdb,NULL)) == REDIS_RDB_LENERR)
goto eoferr;
@@ -1259,8 +1267,9 @@ int rdbLoad(char *filename) {
goto eoferr;
dictExpand(db->dict,db_size);
dictExpand(db->expires,expires_size);
- continue;
+ continue; /* Read type again. */
}
+
/* Read key */
if ((key = rdbLoadStringObject(&rdb)) == NULL) goto eoferr;
/* Read value */