Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
734480be
Commit
734480be
authored
Jan 07, 2015
by
antirez
Browse files
rdbLoad() refactoring to make it simpler to follow.
parent
f50fa6db
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/rdb.c
View file @
734480be
...
@@ -1223,7 +1223,12 @@ int rdbLoad(char *filename) {
...
@@ -1223,7 +1223,12 @@ int rdbLoad(char *filename) {
/* Read type. */
/* Read type. */
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
/* Handle special types. */
if
(
type
==
REDIS_RDB_OPCODE_EXPIRETIME
)
{
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
;
if
((
expiretime
=
rdbLoadTime
(
&
rdb
))
==
-
1
)
goto
eoferr
;
/* We read the time so we need to read the object type again. */
/* We read the time so we need to read the object type again. */
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
...
@@ -1231,27 +1236,30 @@ int rdbLoad(char *filename) {
...
@@ -1231,27 +1236,30 @@ int rdbLoad(char *filename) {
* into milliseconds. */
* into milliseconds. */
expiretime
*=
1000
;
expiretime
*=
1000
;
}
else
if
(
type
==
REDIS_RDB_OPCODE_EXPIRETIME_MS
)
{
}
else
if
(
type
==
REDIS_RDB_OPCODE_EXPIRETIME_MS
)
{
/*
M
illiseconds precision expire times introduced
with RDB
/*
EXPIRETIME_MS: m
illiseconds precision expire times introduced
*
ver
sion
3
. */
*
with RDB v3. Like EXPIRETIME but no with more preci
sion. */
if
((
expiretime
=
rdbLoadMillisecondTime
(
&
rdb
))
==
-
1
)
goto
eoferr
;
if
((
expiretime
=
rdbLoadMillisecondTime
(
&
rdb
))
==
-
1
)
goto
eoferr
;
/* We read the time so we need to read the object type again. */
/* We read the time so we need to read the object type again. */
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
}
}
else
if
(
type
==
REDIS_RDB_OPCODE_EOF
)
{
/* EOF: End of file, exit the main loop. */
if
(
type
==
REDIS_RDB_OPCODE_EOF
)
break
;
break
;
}
else
if
(
type
==
REDIS_RDB_OPCODE_SELECTDB
)
{
/* Handle special opcodes: SELECTDB, RESIZEDB, AUX. */
/* SELECTDB: Select the specified database. */
if
(
type
==
REDIS_RDB_OPCODE_SELECTDB
)
{
if
((
dbid
=
rdbLoadLen
(
&
rdb
,
NULL
))
==
REDIS_RDB_LENERR
)
if
((
dbid
=
rdbLoadLen
(
&
rdb
,
NULL
))
==
REDIS_RDB_LENERR
)
goto
eoferr
;
goto
eoferr
;
if
(
dbid
>=
(
unsigned
)
server
.
dbnum
)
{
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
);
exit
(
1
);
}
}
db
=
server
.
db
+
dbid
;
db
=
server
.
db
+
dbid
;
continue
;
continue
;
/* Read type again. */
}
else
if
(
type
==
REDIS_RDB_OPCODE_RESIZEDB
)
{
}
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
;
uint32_t
db_size
,
expires_size
;
if
((
db_size
=
rdbLoadLen
(
&
rdb
,
NULL
))
==
REDIS_RDB_LENERR
)
if
((
db_size
=
rdbLoadLen
(
&
rdb
,
NULL
))
==
REDIS_RDB_LENERR
)
goto
eoferr
;
goto
eoferr
;
...
@@ -1259,8 +1267,9 @@ int rdbLoad(char *filename) {
...
@@ -1259,8 +1267,9 @@ int rdbLoad(char *filename) {
goto
eoferr
;
goto
eoferr
;
dictExpand
(
db
->
dict
,
db_size
);
dictExpand
(
db
->
dict
,
db_size
);
dictExpand
(
db
->
expires
,
expires_size
);
dictExpand
(
db
->
expires
,
expires_size
);
continue
;
continue
;
/* Read type again. */
}
}
/* Read key */
/* Read key */
if
((
key
=
rdbLoadStringObject
(
&
rdb
))
==
NULL
)
goto
eoferr
;
if
((
key
=
rdbLoadStringObject
(
&
rdb
))
==
NULL
)
goto
eoferr
;
/* Read value */
/* Read value */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment