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
f48cd4b9
Commit
f48cd4b9
authored
Dec 21, 2011
by
antirez
Browse files
some RDB server struct fields renamed.
parent
ff2145ad
Changes
8
Show whitespace changes
Inline
Side-by-side
src/aof.c
View file @
f48cd4b9
...
@@ -144,7 +144,7 @@ void flushAppendOnlyFile(int force) {
...
@@ -144,7 +144,7 @@ void flushAppendOnlyFile(int force) {
/* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
/* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
* children doing I/O in the background. */
* children doing I/O in the background. */
if
(
server
.
aof_no_fsync_on_rewrite
&&
if
(
server
.
aof_no_fsync_on_rewrite
&&
(
server
.
aof_child_pid
!=
-
1
||
server
.
bgsave
childpid
!=
-
1
))
(
server
.
aof_child_pid
!=
-
1
||
server
.
rdb_
child
_
pid
!=
-
1
))
return
;
return
;
/* Perform the fsync if needed. */
/* Perform the fsync if needed. */
...
@@ -815,7 +815,7 @@ int rewriteAppendOnlyFileBackground(void) {
...
@@ -815,7 +815,7 @@ int rewriteAppendOnlyFileBackground(void) {
void
bgrewriteaofCommand
(
redisClient
*
c
)
{
void
bgrewriteaofCommand
(
redisClient
*
c
)
{
if
(
server
.
aof_child_pid
!=
-
1
)
{
if
(
server
.
aof_child_pid
!=
-
1
)
{
addReplyError
(
c
,
"Background append only file rewriting already in progress"
);
addReplyError
(
c
,
"Background append only file rewriting already in progress"
);
}
else
if
(
server
.
bgsave
childpid
!=
-
1
)
{
}
else
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
{
server
.
aof_rewrite_scheduled
=
1
;
server
.
aof_rewrite_scheduled
=
1
;
addReplyStatus
(
c
,
"Background append only file rewriting scheduled"
);
addReplyStatus
(
c
,
"Background append only file rewriting scheduled"
);
}
else
if
(
rewriteAppendOnlyFileBackground
()
==
REDIS_OK
)
{
}
else
if
(
rewriteAppendOnlyFileBackground
()
==
REDIS_OK
)
{
...
...
src/config.c
View file @
f48cd4b9
...
@@ -201,7 +201,7 @@ void loadServerConfigFromString(char *config) {
...
@@ -201,7 +201,7 @@ void loadServerConfigFromString(char *config) {
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"glueoutputbuf"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"glueoutputbuf"
))
{
redisLog
(
REDIS_WARNING
,
"Deprecated configuration directive:
\"
%s
\"
"
,
argv
[
0
]);
redisLog
(
REDIS_WARNING
,
"Deprecated configuration directive:
\"
%s
\"
"
,
argv
[
0
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"rdbcompression"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"rdbcompression"
)
&&
argc
==
2
)
{
if
((
server
.
rdbcompression
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
if
((
server
.
rdb
_
compression
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
}
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"activerehashing"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"activerehashing"
)
&&
argc
==
2
)
{
...
@@ -256,8 +256,8 @@ void loadServerConfigFromString(char *config) {
...
@@ -256,8 +256,8 @@ void loadServerConfigFromString(char *config) {
zfree
(
server
.
pidfile
);
zfree
(
server
.
pidfile
);
server
.
pidfile
=
zstrdup
(
argv
[
1
]);
server
.
pidfile
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"dbfilename"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"dbfilename"
)
&&
argc
==
2
)
{
zfree
(
server
.
dbfilename
);
zfree
(
server
.
r
db
_
filename
);
server
.
dbfilename
=
zstrdup
(
argv
[
1
]);
server
.
r
db
_
filename
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"hash-max-zipmap-entries"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"hash-max-zipmap-entries"
)
&&
argc
==
2
)
{
server
.
hash_max_zipmap_entries
=
memtoll
(
argv
[
1
],
NULL
);
server
.
hash_max_zipmap_entries
=
memtoll
(
argv
[
1
],
NULL
);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"hash-max-zipmap-value"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"hash-max-zipmap-value"
)
&&
argc
==
2
)
{
...
@@ -376,8 +376,8 @@ void configSetCommand(redisClient *c) {
...
@@ -376,8 +376,8 @@ void configSetCommand(redisClient *c) {
o
=
c
->
argv
[
3
];
o
=
c
->
argv
[
3
];
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"dbfilename"
))
{
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"dbfilename"
))
{
zfree
(
server
.
dbfilename
);
zfree
(
server
.
r
db
_
filename
);
server
.
dbfilename
=
zstrdup
(
o
->
ptr
);
server
.
r
db
_
filename
=
zstrdup
(
o
->
ptr
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"requirepass"
))
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"requirepass"
))
{
zfree
(
server
.
requirepass
);
zfree
(
server
.
requirepass
);
server
.
requirepass
=
((
char
*
)
o
->
ptr
)[
0
]
?
zstrdup
(
o
->
ptr
)
:
NULL
;
server
.
requirepass
=
((
char
*
)
o
->
ptr
)[
0
]
?
zstrdup
(
o
->
ptr
)
:
NULL
;
...
@@ -567,7 +567,7 @@ void configGetCommand(redisClient *c) {
...
@@ -567,7 +567,7 @@ void configGetCommand(redisClient *c) {
}
}
if
(
stringmatch
(
pattern
,
"dbfilename"
,
0
))
{
if
(
stringmatch
(
pattern
,
"dbfilename"
,
0
))
{
addReplyBulkCString
(
c
,
"dbfilename"
);
addReplyBulkCString
(
c
,
"dbfilename"
);
addReplyBulkCString
(
c
,
server
.
dbfilename
);
addReplyBulkCString
(
c
,
server
.
r
db
_
filename
);
matches
++
;
matches
++
;
}
}
if
(
stringmatch
(
pattern
,
"requirepass"
,
0
))
{
if
(
stringmatch
(
pattern
,
"requirepass"
,
0
))
{
...
...
src/db.c
View file @
f48cd4b9
...
@@ -40,7 +40,7 @@ robj *lookupKey(redisDb *db, robj *key) {
...
@@ -40,7 +40,7 @@ robj *lookupKey(redisDb *db, robj *key) {
/* Update the access time for the aging algorithm.
/* Update the access time for the aging algorithm.
* Don't do it if we have a saving child, as this will trigger
* Don't do it if we have a saving child, as this will trigger
* a copy on write madness. */
* a copy on write madness. */
if
(
server
.
bgsave
childpid
==
-
1
&&
server
.
aof_child_pid
==
-
1
)
if
(
server
.
rdb_
child
_
pid
==
-
1
&&
server
.
aof_child_pid
==
-
1
)
val
->
lru
=
server
.
lruclock
;
val
->
lru
=
server
.
lruclock
;
server
.
stat_keyspace_hits
++
;
server
.
stat_keyspace_hits
++
;
return
val
;
return
val
;
...
@@ -210,15 +210,15 @@ void flushallCommand(redisClient *c) {
...
@@ -210,15 +210,15 @@ void flushallCommand(redisClient *c) {
signalFlushedDb
(
-
1
);
signalFlushedDb
(
-
1
);
server
.
dirty
+=
emptyDb
();
server
.
dirty
+=
emptyDb
();
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
if
(
server
.
bgsave
childpid
!=
-
1
)
{
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
{
kill
(
server
.
bgsave
childpid
,
SIGKILL
);
kill
(
server
.
rdb_
child
_
pid
,
SIGKILL
);
rdbRemoveTempFile
(
server
.
bgsave
childpid
);
rdbRemoveTempFile
(
server
.
rdb_
child
_
pid
);
}
}
if
(
server
.
saveparamslen
>
0
)
{
if
(
server
.
saveparamslen
>
0
)
{
/* Normally rdbSave() will reset dirty, but we don't want this here
/* Normally rdbSave() will reset dirty, but we don't want this here
* as otherwise FLUSHALL will not be replicated nor put into the AOF. */
* as otherwise FLUSHALL will not be replicated nor put into the AOF. */
int
saved_dirty
=
server
.
dirty
;
int
saved_dirty
=
server
.
dirty
;
rdbSave
(
server
.
dbfilename
);
rdbSave
(
server
.
r
db
_
filename
);
server
.
dirty
=
saved_dirty
;
server
.
dirty
=
saved_dirty
;
}
}
server
.
dirty
++
;
server
.
dirty
++
;
...
...
src/debug.c
View file @
f48cd4b9
...
@@ -216,12 +216,12 @@ void debugCommand(redisClient *c) {
...
@@ -216,12 +216,12 @@ void debugCommand(redisClient *c) {
if
(
c
->
argc
>=
3
)
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
if
(
c
->
argc
>=
3
)
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
redisAssertWithInfo
(
c
,
c
->
argv
[
0
],
1
==
2
);
redisAssertWithInfo
(
c
,
c
->
argv
[
0
],
1
==
2
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"reload"
))
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"reload"
))
{
if
(
rdbSave
(
server
.
dbfilename
)
!=
REDIS_OK
)
{
if
(
rdbSave
(
server
.
r
db
_
filename
)
!=
REDIS_OK
)
{
addReply
(
c
,
shared
.
err
);
addReply
(
c
,
shared
.
err
);
return
;
return
;
}
}
emptyDb
();
emptyDb
();
if
(
rdbLoad
(
server
.
dbfilename
)
!=
REDIS_OK
)
{
if
(
rdbLoad
(
server
.
r
db
_
filename
)
!=
REDIS_OK
)
{
addReplyError
(
c
,
"Error trying to load the RDB dump"
);
addReplyError
(
c
,
"Error trying to load the RDB dump"
);
return
;
return
;
}
}
...
...
src/rdb.c
View file @
f48cd4b9
...
@@ -253,7 +253,7 @@ int rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
...
@@ -253,7 +253,7 @@ int rdbSaveRawString(rio *rdb, unsigned char *s, size_t len) {
/* Try LZF compression - under 20 bytes it's unable to compress even
/* Try LZF compression - under 20 bytes it's unable to compress even
* aaaaaaaaaaaaaaaaaa so skip it */
* aaaaaaaaaaaaaaaaaa so skip it */
if
(
server
.
rdbcompression
&&
len
>
20
)
{
if
(
server
.
rdb
_
compression
&&
len
>
20
)
{
n
=
rdbSaveLzfStringObject
(
rdb
,
s
,
len
);
n
=
rdbSaveLzfStringObject
(
rdb
,
s
,
len
);
if
(
n
==
-
1
)
return
-
1
;
if
(
n
==
-
1
)
return
-
1
;
if
(
n
>
0
)
return
n
;
if
(
n
>
0
)
return
n
;
...
@@ -670,7 +670,7 @@ int rdbSaveBackground(char *filename) {
...
@@ -670,7 +670,7 @@ int rdbSaveBackground(char *filename) {
pid_t
childpid
;
pid_t
childpid
;
long
long
start
;
long
long
start
;
if
(
server
.
bgsave
childpid
!=
-
1
)
return
REDIS_ERR
;
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
return
REDIS_ERR
;
server
.
dirty_before_bgsave
=
server
.
dirty
;
server
.
dirty_before_bgsave
=
server
.
dirty
;
...
@@ -692,7 +692,7 @@ int rdbSaveBackground(char *filename) {
...
@@ -692,7 +692,7 @@ int rdbSaveBackground(char *filename) {
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
redisLog
(
REDIS_NOTICE
,
"Background saving started by pid %d"
,
childpid
);
redisLog
(
REDIS_NOTICE
,
"Background saving started by pid %d"
,
childpid
);
server
.
bgsave
childpid
=
childpid
;
server
.
rdb_
child
_
pid
=
childpid
;
updateDictResizePolicy
();
updateDictResizePolicy
();
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
@@ -1062,20 +1062,20 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) {
...
@@ -1062,20 +1062,20 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) {
}
else
{
}
else
{
redisLog
(
REDIS_WARNING
,
redisLog
(
REDIS_WARNING
,
"Background saving terminated by signal %d"
,
bysignal
);
"Background saving terminated by signal %d"
,
bysignal
);
rdbRemoveTempFile
(
server
.
bgsave
childpid
);
rdbRemoveTempFile
(
server
.
rdb_
child
_
pid
);
}
}
server
.
bgsave
childpid
=
-
1
;
server
.
rdb_
child
_
pid
=
-
1
;
/* Possibly there are slaves waiting for a BGSAVE in order to be served
/* Possibly there are slaves waiting for a BGSAVE in order to be served
* (the first stage of SYNC is a bulk transfer of dump.rdb) */
* (the first stage of SYNC is a bulk transfer of dump.rdb) */
updateSlavesWaitingBgsave
(
exitcode
==
0
?
REDIS_OK
:
REDIS_ERR
);
updateSlavesWaitingBgsave
(
exitcode
==
0
?
REDIS_OK
:
REDIS_ERR
);
}
}
void
saveCommand
(
redisClient
*
c
)
{
void
saveCommand
(
redisClient
*
c
)
{
if
(
server
.
bgsave
childpid
!=
-
1
)
{
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
{
addReplyError
(
c
,
"Background save already in progress"
);
addReplyError
(
c
,
"Background save already in progress"
);
return
;
return
;
}
}
if
(
rdbSave
(
server
.
dbfilename
)
==
REDIS_OK
)
{
if
(
rdbSave
(
server
.
r
db
_
filename
)
==
REDIS_OK
)
{
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
}
else
{
}
else
{
addReply
(
c
,
shared
.
err
);
addReply
(
c
,
shared
.
err
);
...
@@ -1083,11 +1083,11 @@ void saveCommand(redisClient *c) {
...
@@ -1083,11 +1083,11 @@ void saveCommand(redisClient *c) {
}
}
void
bgsaveCommand
(
redisClient
*
c
)
{
void
bgsaveCommand
(
redisClient
*
c
)
{
if
(
server
.
bgsave
childpid
!=
-
1
)
{
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
{
addReplyError
(
c
,
"Background save already in progress"
);
addReplyError
(
c
,
"Background save already in progress"
);
}
else
if
(
server
.
aof_child_pid
!=
-
1
)
{
}
else
if
(
server
.
aof_child_pid
!=
-
1
)
{
addReplyError
(
c
,
"Can't BGSAVE while AOF log rewriting is in progress"
);
addReplyError
(
c
,
"Can't BGSAVE while AOF log rewriting is in progress"
);
}
else
if
(
rdbSaveBackground
(
server
.
dbfilename
)
==
REDIS_OK
)
{
}
else
if
(
rdbSaveBackground
(
server
.
r
db
_
filename
)
==
REDIS_OK
)
{
addReplyStatus
(
c
,
"Background saving started"
);
addReplyStatus
(
c
,
"Background saving started"
);
}
else
{
}
else
{
addReply
(
c
,
shared
.
err
);
addReply
(
c
,
shared
.
err
);
...
...
src/redis.c
View file @
f48cd4b9
...
@@ -563,7 +563,7 @@ void incrementallyRehash(void) {
...
@@ -563,7 +563,7 @@ void incrementallyRehash(void) {
* for dict.c to resize the hash tables accordingly to the fact we have o not
* for dict.c to resize the hash tables accordingly to the fact we have o not
* running childs. */
* running childs. */
void
updateDictResizePolicy
(
void
)
{
void
updateDictResizePolicy
(
void
)
{
if
(
server
.
bgsave
childpid
==
-
1
&&
server
.
aof_child_pid
==
-
1
)
if
(
server
.
rdb_
child
_
pid
==
-
1
&&
server
.
aof_child_pid
==
-
1
)
dictEnableResize
();
dictEnableResize
();
else
else
dictDisableResize
();
dictDisableResize
();
...
@@ -673,7 +673,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
...
@@ -673,7 +673,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
* if we resize the HT while there is the saving child at work actually
* if we resize the HT while there is the saving child at work actually
* a lot of memory movements in the parent will cause a lot of pages
* a lot of memory movements in the parent will cause a lot of pages
* copied. */
* copied. */
if
(
server
.
bgsave
childpid
==
-
1
&&
server
.
aof_child_pid
==
-
1
)
{
if
(
server
.
rdb_
child
_
pid
==
-
1
&&
server
.
aof_child_pid
==
-
1
)
{
if
(
!
(
loops
%
10
))
tryResizeHashTables
();
if
(
!
(
loops
%
10
))
tryResizeHashTables
();
if
(
server
.
activerehashing
)
incrementallyRehash
();
if
(
server
.
activerehashing
)
incrementallyRehash
();
}
}
...
@@ -692,14 +692,14 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
...
@@ -692,14 +692,14 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* Start a scheduled AOF rewrite if this was requested by the user while
/* Start a scheduled AOF rewrite if this was requested by the user while
* a BGSAVE was in progress. */
* a BGSAVE was in progress. */
if
(
server
.
bgsave
childpid
==
-
1
&&
server
.
aof_child_pid
==
-
1
&&
if
(
server
.
rdb_
child
_
pid
==
-
1
&&
server
.
aof_child_pid
==
-
1
&&
server
.
aof_rewrite_scheduled
)
server
.
aof_rewrite_scheduled
)
{
{
rewriteAppendOnlyFileBackground
();
rewriteAppendOnlyFileBackground
();
}
}
/* Check if a background saving or AOF rewrite in progress terminated. */
/* Check if a background saving or AOF rewrite in progress terminated. */
if
(
server
.
bgsave
childpid
!=
-
1
||
server
.
aof_child_pid
!=
-
1
)
{
if
(
server
.
rdb_
child
_
pid
!=
-
1
||
server
.
aof_child_pid
!=
-
1
)
{
int
statloc
;
int
statloc
;
pid_t
pid
;
pid_t
pid
;
...
@@ -709,7 +709,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
...
@@ -709,7 +709,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
if
(
WIFSIGNALED
(
statloc
))
bysignal
=
WTERMSIG
(
statloc
);
if
(
WIFSIGNALED
(
statloc
))
bysignal
=
WTERMSIG
(
statloc
);
if
(
pid
==
server
.
bgsave
childpid
)
{
if
(
pid
==
server
.
rdb_
child
_
pid
)
{
backgroundSaveDoneHandler
(
exitcode
,
bysignal
);
backgroundSaveDoneHandler
(
exitcode
,
bysignal
);
}
else
{
}
else
{
backgroundRewriteDoneHandler
(
exitcode
,
bysignal
);
backgroundRewriteDoneHandler
(
exitcode
,
bysignal
);
...
@@ -728,13 +728,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
...
@@ -728,13 +728,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
now
-
server
.
lastsave
>
sp
->
seconds
)
{
now
-
server
.
lastsave
>
sp
->
seconds
)
{
redisLog
(
REDIS_NOTICE
,
"%d changes in %d seconds. Saving..."
,
redisLog
(
REDIS_NOTICE
,
"%d changes in %d seconds. Saving..."
,
sp
->
changes
,
sp
->
seconds
);
sp
->
changes
,
sp
->
seconds
);
rdbSaveBackground
(
server
.
dbfilename
);
rdbSaveBackground
(
server
.
r
db
_
filename
);
break
;
break
;
}
}
}
}
/* Trigger an AOF rewrite if needed */
/* Trigger an AOF rewrite if needed */
if
(
server
.
bgsave
childpid
==
-
1
&&
if
(
server
.
rdb_
child
_
pid
==
-
1
&&
server
.
aof_child_pid
==
-
1
&&
server
.
aof_child_pid
==
-
1
&&
server
.
aof_rewrite_perc
&&
server
.
aof_rewrite_perc
&&
server
.
aof_current_size
>
server
.
aof_rewrite_min_size
)
server
.
aof_current_size
>
server
.
aof_rewrite_min_size
)
...
@@ -885,10 +885,10 @@ void initServerConfig() {
...
@@ -885,10 +885,10 @@ void initServerConfig() {
server
.
aof_selected_db
=
-
1
;
/* Make sure the first time will not match */
server
.
aof_selected_db
=
-
1
;
/* Make sure the first time will not match */
server
.
aof_flush_postponed_start
=
0
;
server
.
aof_flush_postponed_start
=
0
;
server
.
pidfile
=
zstrdup
(
"/var/run/redis.pid"
);
server
.
pidfile
=
zstrdup
(
"/var/run/redis.pid"
);
server
.
dbfilename
=
zstrdup
(
"dump.rdb"
);
server
.
r
db
_
filename
=
zstrdup
(
"dump.rdb"
);
server
.
aof_filename
=
zstrdup
(
"appendonly.aof"
);
server
.
aof_filename
=
zstrdup
(
"appendonly.aof"
);
server
.
requirepass
=
NULL
;
server
.
requirepass
=
NULL
;
server
.
rdbcompression
=
1
;
server
.
rdb
_
compression
=
1
;
server
.
activerehashing
=
1
;
server
.
activerehashing
=
1
;
server
.
maxclients
=
REDIS_MAX_CLIENTS
;
server
.
maxclients
=
REDIS_MAX_CLIENTS
;
server
.
bpop_blocked_clients
=
0
;
server
.
bpop_blocked_clients
=
0
;
...
@@ -1044,7 +1044,7 @@ void initServer() {
...
@@ -1044,7 +1044,7 @@ void initServer() {
listSetFreeMethod
(
server
.
pubsub_patterns
,
freePubsubPattern
);
listSetFreeMethod
(
server
.
pubsub_patterns
,
freePubsubPattern
);
listSetMatchMethod
(
server
.
pubsub_patterns
,
listMatchPubsubPattern
);
listSetMatchMethod
(
server
.
pubsub_patterns
,
listMatchPubsubPattern
);
server
.
cronloops
=
0
;
server
.
cronloops
=
0
;
server
.
bgsave
childpid
=
-
1
;
server
.
rdb_
child
_
pid
=
-
1
;
server
.
aof_child_pid
=
-
1
;
server
.
aof_child_pid
=
-
1
;
server
.
aof_rewrite_buf
=
sdsempty
();
server
.
aof_rewrite_buf
=
sdsempty
();
server
.
aof_buf
=
sdsempty
();
server
.
aof_buf
=
sdsempty
();
...
@@ -1305,10 +1305,10 @@ int prepareForShutdown(int flags) {
...
@@ -1305,10 +1305,10 @@ int prepareForShutdown(int flags) {
/* Kill the saving child if there is a background saving in progress.
/* Kill the saving child if there is a background saving in progress.
We want to avoid race conditions, for instance our saving child may
We want to avoid race conditions, for instance our saving child may
overwrite the synchronous saving did by SHUTDOWN. */
overwrite the synchronous saving did by SHUTDOWN. */
if
(
server
.
bgsave
childpid
!=
-
1
)
{
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
{
redisLog
(
REDIS_WARNING
,
"There is a child saving an .rdb. Killing it!"
);
redisLog
(
REDIS_WARNING
,
"There is a child saving an .rdb. Killing it!"
);
kill
(
server
.
bgsave
childpid
,
SIGKILL
);
kill
(
server
.
rdb_
child
_
pid
,
SIGKILL
);
rdbRemoveTempFile
(
server
.
bgsave
childpid
);
rdbRemoveTempFile
(
server
.
rdb_
child
_
pid
);
}
}
if
(
server
.
aof_state
!=
REDIS_AOF_OFF
)
{
if
(
server
.
aof_state
!=
REDIS_AOF_OFF
)
{
/* Kill the AOF saving child as the AOF we already have may be longer
/* Kill the AOF saving child as the AOF we already have may be longer
...
@@ -1325,7 +1325,7 @@ int prepareForShutdown(int flags) {
...
@@ -1325,7 +1325,7 @@ int prepareForShutdown(int flags) {
if
((
server
.
saveparamslen
>
0
&&
!
nosave
)
||
save
)
{
if
((
server
.
saveparamslen
>
0
&&
!
nosave
)
||
save
)
{
redisLog
(
REDIS_NOTICE
,
"Saving the final RDB snapshot before exiting."
);
redisLog
(
REDIS_NOTICE
,
"Saving the final RDB snapshot before exiting."
);
/* Snapshotting. Perform a SYNC SAVE and exit */
/* Snapshotting. Perform a SYNC SAVE and exit */
if
(
rdbSave
(
server
.
dbfilename
)
!=
REDIS_OK
)
{
if
(
rdbSave
(
server
.
r
db
_
filename
)
!=
REDIS_OK
)
{
/* Ooops.. error saving! The best we can do is to continue
/* Ooops.. error saving! The best we can do is to continue
* operating. Note that if there was a background saving process,
* operating. Note that if there was a background saving process,
* in the next cron() Redis will be notified that the background
* in the next cron() Redis will be notified that the background
...
@@ -1499,7 +1499,7 @@ sds genRedisInfoString(char *section) {
...
@@ -1499,7 +1499,7 @@ sds genRedisInfoString(char *section) {
server
.
loading
,
server
.
loading
,
server
.
aof_state
!=
REDIS_AOF_OFF
,
server
.
aof_state
!=
REDIS_AOF_OFF
,
server
.
dirty
,
server
.
dirty
,
server
.
bgsave
childpid
!=
-
1
,
server
.
rdb_
child
_
pid
!=
-
1
,
server
.
lastsave
,
server
.
lastsave
,
server
.
aof_child_pid
!=
-
1
);
server
.
aof_child_pid
!=
-
1
);
...
@@ -2102,7 +2102,7 @@ int main(int argc, char **argv) {
...
@@ -2102,7 +2102,7 @@ int main(int argc, char **argv) {
if
(
loadAppendOnlyFile
(
server
.
aof_filename
)
==
REDIS_OK
)
if
(
loadAppendOnlyFile
(
server
.
aof_filename
)
==
REDIS_OK
)
redisLog
(
REDIS_NOTICE
,
"DB loaded from append only file: %.3f seconds"
,(
float
)(
ustime
()
-
start
)
/
1000000
);
redisLog
(
REDIS_NOTICE
,
"DB loaded from append only file: %.3f seconds"
,(
float
)(
ustime
()
-
start
)
/
1000000
);
}
else
{
}
else
{
if
(
rdbLoad
(
server
.
dbfilename
)
==
REDIS_OK
)
{
if
(
rdbLoad
(
server
.
r
db
_
filename
)
==
REDIS_OK
)
{
redisLog
(
REDIS_NOTICE
,
"DB loaded from disk: %.3f seconds"
,
redisLog
(
REDIS_NOTICE
,
"DB loaded from disk: %.3f seconds"
,
(
float
)(
ustime
()
-
start
)
/
1000000
);
(
float
)(
ustime
()
-
start
)
/
1000000
);
}
else
if
(
errno
!=
ENOENT
)
{
}
else
if
(
errno
!=
ENOENT
)
{
...
...
src/redis.h
View file @
f48cd4b9
...
@@ -570,11 +570,11 @@ struct redisServer {
...
@@ -570,11 +570,11 @@ struct redisServer {
/* RDB persistence */
/* RDB persistence */
long
long
dirty
;
/* Changes to DB from the last save */
long
long
dirty
;
/* Changes to DB from the last save */
long
long
dirty_before_bgsave
;
/* Used to restore dirty on failed BGSAVE */
long
long
dirty_before_bgsave
;
/* Used to restore dirty on failed BGSAVE */
pid_t
bgsave
childpid
;
/* PID of RDB saving child */
pid_t
rdb_
child
_
pid
;
/* PID of RDB saving child */
struct
saveparam
*
saveparams
;
/* Save points array for RDB */
struct
saveparam
*
saveparams
;
/* Save points array for RDB */
int
saveparamslen
;
/* Number of saving points */
int
saveparamslen
;
/* Number of saving points */
char
*
dbfilename
;
/* Name of RDB file */
char
*
r
db
_
filename
;
/* Name of RDB file */
int
rdbcompression
;
/* Use compression in RDB? */
int
rdb
_
compression
;
/* Use compression in RDB? */
/* Logging */
/* Logging */
char
*
logfile
;
/* Path of log file */
char
*
logfile
;
/* Path of log file */
int
syslog_enabled
;
/* Is syslog enabled? */
int
syslog_enabled
;
/* Is syslog enabled? */
...
...
src/replication.c
View file @
f48cd4b9
...
@@ -106,7 +106,7 @@ void syncCommand(redisClient *c) {
...
@@ -106,7 +106,7 @@ void syncCommand(redisClient *c) {
redisLog
(
REDIS_NOTICE
,
"Slave ask for synchronization"
);
redisLog
(
REDIS_NOTICE
,
"Slave ask for synchronization"
);
/* Here we need to check if there is a background saving operation
/* Here we need to check if there is a background saving operation
* in progress, or if it is required to start one */
* in progress, or if it is required to start one */
if
(
server
.
bgsave
childpid
!=
-
1
)
{
if
(
server
.
rdb_
child
_
pid
!=
-
1
)
{
/* Ok a background save is in progress. Let's check if it is a good
/* Ok a background save is in progress. Let's check if it is a good
* one for replication, i.e. if there is another slave that is
* one for replication, i.e. if there is another slave that is
* registering differences since the server forked to save */
* registering differences since the server forked to save */
...
@@ -135,7 +135,7 @@ void syncCommand(redisClient *c) {
...
@@ -135,7 +135,7 @@ void syncCommand(redisClient *c) {
}
else
{
}
else
{
/* Ok we don't have a BGSAVE in progress, let's start one */
/* Ok we don't have a BGSAVE in progress, let's start one */
redisLog
(
REDIS_NOTICE
,
"Starting BGSAVE for SYNC"
);
redisLog
(
REDIS_NOTICE
,
"Starting BGSAVE for SYNC"
);
if
(
rdbSaveBackground
(
server
.
dbfilename
)
!=
REDIS_OK
)
{
if
(
rdbSaveBackground
(
server
.
r
db
_
filename
)
!=
REDIS_OK
)
{
redisLog
(
REDIS_NOTICE
,
"Replication failed, can't BGSAVE"
);
redisLog
(
REDIS_NOTICE
,
"Replication failed, can't BGSAVE"
);
addReplyError
(
c
,
"Unable to perform background save"
);
addReplyError
(
c
,
"Unable to perform background save"
);
return
;
return
;
...
@@ -229,7 +229,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {
...
@@ -229,7 +229,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {
redisLog
(
REDIS_WARNING
,
"SYNC failed. BGSAVE child returned an error"
);
redisLog
(
REDIS_WARNING
,
"SYNC failed. BGSAVE child returned an error"
);
continue
;
continue
;
}
}
if
((
slave
->
repldbfd
=
open
(
server
.
dbfilename
,
O_RDONLY
))
==
-
1
||
if
((
slave
->
repldbfd
=
open
(
server
.
r
db
_
filename
,
O_RDONLY
))
==
-
1
||
redis_fstat
(
slave
->
repldbfd
,
&
buf
)
==
-
1
)
{
redis_fstat
(
slave
->
repldbfd
,
&
buf
)
==
-
1
)
{
freeClient
(
slave
);
freeClient
(
slave
);
redisLog
(
REDIS_WARNING
,
"SYNC failed. Can't open/stat DB after BGSAVE: %s"
,
strerror
(
errno
));
redisLog
(
REDIS_WARNING
,
"SYNC failed. Can't open/stat DB after BGSAVE: %s"
,
strerror
(
errno
));
...
@@ -246,7 +246,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {
...
@@ -246,7 +246,7 @@ void updateSlavesWaitingBgsave(int bgsaveerr) {
}
}
}
}
if
(
startbgsave
)
{
if
(
startbgsave
)
{
if
(
rdbSaveBackground
(
server
.
dbfilename
)
!=
REDIS_OK
)
{
if
(
rdbSaveBackground
(
server
.
r
db
_
filename
)
!=
REDIS_OK
)
{
listIter
li
;
listIter
li
;
listRewind
(
server
.
slaves
,
&
li
);
listRewind
(
server
.
slaves
,
&
li
);
...
@@ -333,7 +333,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -333,7 +333,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
server
.
repl_transfer_left
-=
nread
;
server
.
repl_transfer_left
-=
nread
;
/* Check if the transfer is now complete */
/* Check if the transfer is now complete */
if
(
server
.
repl_transfer_left
==
0
)
{
if
(
server
.
repl_transfer_left
==
0
)
{
if
(
rename
(
server
.
repl_transfer_tmpfile
,
server
.
dbfilename
)
==
-
1
)
{
if
(
rename
(
server
.
repl_transfer_tmpfile
,
server
.
r
db
_
filename
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s"
,
strerror
(
errno
));
redisLog
(
REDIS_WARNING
,
"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s"
,
strerror
(
errno
));
replicationAbortSyncTransfer
();
replicationAbortSyncTransfer
();
return
;
return
;
...
@@ -345,7 +345,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -345,7 +345,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
* rdbLoad() will call the event loop to process events from time to
* rdbLoad() will call the event loop to process events from time to
* time for non blocking loading. */
* time for non blocking loading. */
aeDeleteFileEvent
(
server
.
el
,
server
.
repl_transfer_s
,
AE_READABLE
);
aeDeleteFileEvent
(
server
.
el
,
server
.
repl_transfer_s
,
AE_READABLE
);
if
(
rdbLoad
(
server
.
dbfilename
)
!=
REDIS_OK
)
{
if
(
rdbLoad
(
server
.
r
db
_
filename
)
!=
REDIS_OK
)
{
redisLog
(
REDIS_WARNING
,
"Failed trying to load the MASTER synchronization DB from disk"
);
redisLog
(
REDIS_WARNING
,
"Failed trying to load the MASTER synchronization DB from disk"
);
replicationAbortSyncTransfer
();
replicationAbortSyncTransfer
();
return
;
return
;
...
...
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