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
585af7e2
Commit
585af7e2
authored
May 08, 2010
by
antirez
Browse files
minor changes to improve code readability
parent
242a64f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
585af7e2
...
@@ -3947,10 +3947,9 @@ static robj *rdbLoadObject(int type, FILE *fp) {
...
@@ -3947,10 +3947,9 @@ static robj *rdbLoadObject(int type, FILE *fp) {
static
int
rdbLoad
(
char
*
filename
)
{
static
int
rdbLoad
(
char
*
filename
)
{
FILE
*
fp
;
FILE
*
fp
;
robj
*
keyobj
=
NULL
;
uint32_t
dbid
;
uint32_t
dbid
;
int
type
,
retval
,
rdbver
;
int
type
,
retval
,
rdbver
;
int
dataset_too_big
=
0
;
int
swap_all_values
=
0
;
dict
*
d
=
server
.
db
[
0
].
dict
;
dict
*
d
=
server
.
db
[
0
].
dict
;
redisDb
*
db
=
server
.
db
+
0
;
redisDb
*
db
=
server
.
db
+
0
;
char
buf
[
1024
];
char
buf
[
1024
];
...
@@ -3973,9 +3972,9 @@ static int rdbLoad(char *filename) {
...
@@ -3973,9 +3972,9 @@ static int rdbLoad(char *filename) {
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
while
(
1
)
{
while
(
1
)
{
robj
*
o
;
robj
*
key
,
*
val
;
expiretime
=
-
1
;
expiretime
=
-
1
;
/* Read type. */
/* Read type. */
if
((
type
=
rdbLoadType
(
fp
))
==
-
1
)
goto
eoferr
;
if
((
type
=
rdbLoadType
(
fp
))
==
-
1
)
goto
eoferr
;
if
(
type
==
REDIS_EXPIRETIME
)
{
if
(
type
==
REDIS_EXPIRETIME
)
{
...
@@ -3997,22 +3996,22 @@ static int rdbLoad(char *filename) {
...
@@ -3997,22 +3996,22 @@ static int rdbLoad(char *filename) {
continue
;
continue
;
}
}
/* Read key */
/* Read key */
if
((
key
obj
=
rdbLoadStringObject
(
fp
))
==
NULL
)
goto
eoferr
;
if
((
key
=
rdbLoadStringObject
(
fp
))
==
NULL
)
goto
eoferr
;
/* Read value */
/* Read value */
if
((
o
=
rdbLoadObject
(
type
,
fp
))
==
NULL
)
goto
eoferr
;
if
((
val
=
rdbLoadObject
(
type
,
fp
))
==
NULL
)
goto
eoferr
;
/* Add the new object in the hash table */
/* Add the new object in the hash table */
retval
=
dictAdd
(
d
,
key
obj
,
o
);
retval
=
dictAdd
(
d
,
key
,
val
);
if
(
retval
==
DICT_ERR
)
{
if
(
retval
==
DICT_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Loading DB, duplicated key (%s) found! Unrecoverable error, exiting now."
,
key
obj
->
ptr
);
redisLog
(
REDIS_WARNING
,
"Loading DB, duplicated key (%s) found! Unrecoverable error, exiting now."
,
key
->
ptr
);
exit
(
1
);
exit
(
1
);
}
}
loadedkeys
++
;
loadedkeys
++
;
/* Set the expire time if needed */
/* Set the expire time if needed */
if
(
expiretime
!=
-
1
)
{
if
(
expiretime
!=
-
1
)
{
setExpire
(
db
,
key
obj
,
expiretime
);
setExpire
(
db
,
key
,
expiretime
);
/* Delete this key if already expired */
/* Delete this key if already expired */
if
(
expiretime
<
now
)
{
if
(
expiretime
<
now
)
{
deleteKey
(
db
,
key
obj
);
deleteKey
(
db
,
key
);
continue
;
/* don't try to swap this out */
continue
;
/* don't try to swap this out */
}
}
}
}
...
@@ -4024,15 +4023,15 @@ static int rdbLoad(char *filename) {
...
@@ -4024,15 +4023,15 @@ static int rdbLoad(char *filename) {
* Note that's important to check for this condition before resorting
* Note that's important to check for this condition before resorting
* to random sampling, otherwise we may try to swap already
* to random sampling, otherwise we may try to swap already
* swapped keys. */
* swapped keys. */
if
(
dataset_too_big
)
{
if
(
swap_all_values
)
{
dictEntry
*
de
=
dictFind
(
d
,
key
obj
);
dictEntry
*
de
=
dictFind
(
d
,
key
);
/* de may be NULL since the key already expired */
/* de may be NULL since the key already expired */
if
(
de
)
{
if
(
de
)
{
key
obj
=
dictGetEntryKey
(
de
);
key
=
dictGetEntryKey
(
de
);
o
=
dictGetEntryVal
(
de
);
val
=
dictGetEntryVal
(
de
);
if
(
vmSwapObjectBlocking
(
key
obj
,
o
)
==
REDIS_OK
)
{
if
(
vmSwapObjectBlocking
(
key
,
val
)
==
REDIS_OK
)
{
dictGetEntryVal
(
de
)
=
NULL
;
dictGetEntryVal
(
de
)
=
NULL
;
}
}
}
}
...
@@ -4041,19 +4040,18 @@ static int rdbLoad(char *filename) {
...
@@ -4041,19 +4040,18 @@ static int rdbLoad(char *filename) {
/* If we have still some hope of having some value fitting memory
/* If we have still some hope of having some value fitting memory
* then we try random sampling. */
* then we try random sampling. */
if
(
!
dataset_too_big
&&
server
.
vm_enabled
&&
(
loadedkeys
%
5000
)
==
0
)
{
if
(
!
swap_all_values
&&
server
.
vm_enabled
&&
(
loadedkeys
%
5000
)
==
0
)
{
while
(
zmalloc_used_memory
()
>
server
.
vm_max_memory
)
{
while
(
zmalloc_used_memory
()
>
server
.
vm_max_memory
)
{
if
(
vmSwapOneObjectBlocking
()
==
REDIS_ERR
)
break
;
if
(
vmSwapOneObjectBlocking
()
==
REDIS_ERR
)
break
;
}
}
if
(
zmalloc_used_memory
()
>
server
.
vm_max_memory
)
if
(
zmalloc_used_memory
()
>
server
.
vm_max_memory
)
dataset_too_big
=
1
;
swap_all_values
=
1
;
/* We are already using too much mem */
}
}
}
}
fclose
(
fp
);
fclose
(
fp
);
return
REDIS_OK
;
return
REDIS_OK
;
eoferr:
/* unexpected end of file is handled here with a fatal exit */
eoferr:
/* unexpected end of file is handled here with a fatal exit */
if
(
keyobj
)
decrRefCount
(
keyobj
);
redisLog
(
REDIS_WARNING
,
"Short read or OOM loading DB. Unrecoverable error, aborting now."
);
redisLog
(
REDIS_WARNING
,
"Short read or OOM loading DB. Unrecoverable error, aborting now."
);
exit
(
1
);
exit
(
1
);
return
REDIS_ERR
;
/* Just to avoid warning */
return
REDIS_ERR
;
/* Just to avoid warning */
...
...
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