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
752203d8
Commit
752203d8
authored
May 31, 2010
by
antirez
Browse files
Merge branch 'no-appendfsync-on-rewrite'
parents
d55d5c5d
d5d23dab
Changes
2
Show whitespace changes
Inline
Side-by-side
redis.c
View file @
752203d8
...
@@ -369,6 +369,7 @@ struct redisServer {
...
@@ -369,6 +369,7 @@ struct redisServer {
int
daemonize
;
int
daemonize
;
int
appendonly
;
int
appendonly
;
int
appendfsync
;
int
appendfsync
;
int
no_appendfsync_on_rewrite
;
int
shutdown_asap
;
int
shutdown_asap
;
time_t
lastfsync
;
time_t
lastfsync
;
int
appendfd
;
int
appendfd
;
...
@@ -1385,7 +1386,7 @@ void backgroundRewriteDoneHandler(int statloc) {
...
@@ -1385,7 +1386,7 @@ void backgroundRewriteDoneHandler(int statloc) {
/* If append only is actually enabled... */
/* If append only is actually enabled... */
close
(
server
.
appendfd
);
close
(
server
.
appendfd
);
server
.
appendfd
=
fd
;
server
.
appendfd
=
fd
;
fsync
(
fd
);
if
(
server
.
appendfsync
!=
APPENDFSYNC_NO
)
aof_
fsync
(
fd
);
server
.
appendseldb
=
-
1
;
/* Make sure it will issue SELECT */
server
.
appendseldb
=
-
1
;
/* Make sure it will issue SELECT */
redisLog
(
REDIS_NOTICE
,
"The new append only file was selected for future appends."
);
redisLog
(
REDIS_NOTICE
,
"The new append only file was selected for future appends."
);
}
else
{
}
else
{
...
@@ -1685,6 +1686,7 @@ static void initServerConfig() {
...
@@ -1685,6 +1686,7 @@ static void initServerConfig() {
server
.
daemonize
=
0
;
server
.
daemonize
=
0
;
server
.
appendonly
=
0
;
server
.
appendonly
=
0
;
server
.
appendfsync
=
APPENDFSYNC_EVERYSEC
;
server
.
appendfsync
=
APPENDFSYNC_EVERYSEC
;
server
.
no_appendfsync_on_rewrite
=
0
;
server
.
lastfsync
=
time
(
NULL
);
server
.
lastfsync
=
time
(
NULL
);
server
.
appendfd
=
-
1
;
server
.
appendfd
=
-
1
;
server
.
appendseldb
=
-
1
;
/* Make sure the first time will not match */
server
.
appendseldb
=
-
1
;
/* Make sure the first time will not match */
...
@@ -1941,6 +1943,11 @@ static void loadServerConfig(char *filename) {
...
@@ -1941,6 +1943,11 @@ static void loadServerConfig(char *filename) {
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"appendfilename"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"appendfilename"
)
&&
argc
==
2
)
{
zfree
(
server
.
appendfilename
);
zfree
(
server
.
appendfilename
);
server
.
appendfilename
=
zstrdup
(
argv
[
1
]);
server
.
appendfilename
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"no-appendfsync-on-rewrite"
)
&&
argc
==
2
)
{
if
((
server
.
no_appendfsync_on_rewrite
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"appendfsync"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"appendfsync"
)
&&
argc
==
2
)
{
if
(
!
strcasecmp
(
argv
[
1
],
"no"
))
{
if
(
!
strcasecmp
(
argv
[
1
],
"no"
))
{
server
.
appendfsync
=
APPENDFSYNC_NO
;
server
.
appendfsync
=
APPENDFSYNC_NO
;
...
@@ -4209,7 +4216,7 @@ static int prepareForShutdown() {
...
@@ -4209,7 +4216,7 @@ static int prepareForShutdown() {
}
}
if
(
server
.
appendonly
)
{
if
(
server
.
appendonly
)
{
/* Append only file: fsync() the AOF and exit */
/* Append only file: fsync() the AOF and exit */
fsync
(
server
.
appendfd
);
aof_
fsync
(
server
.
appendfd
);
if
(
server
.
vm_enabled
)
unlink
(
server
.
vm_swap_file
);
if
(
server
.
vm_enabled
)
unlink
(
server
.
vm_swap_file
);
}
else
{
}
else
{
/* Snapshotting. Perform a SYNC SAVE and exit */
/* Snapshotting. Perform a SYNC SAVE and exit */
...
@@ -8266,6 +8273,11 @@ static void flushAppendOnlyFile(void) {
...
@@ -8266,6 +8273,11 @@ static void flushAppendOnlyFile(void) {
sdsfree
(
server
.
aofbuf
);
sdsfree
(
server
.
aofbuf
);
server
.
aofbuf
=
sdsempty
();
server
.
aofbuf
=
sdsempty
();
/* Don't Fsync if no-appendfsync-on-rewrite is set to yes and we have
* childs performing heavy I/O on disk. */
if
(
server
.
no_appendfsync_on_rewrite
&&
(
server
.
bgrewritechildpid
!=
-
1
||
server
.
bgsavechildpid
!=
-
1
))
return
;
/* Fsync if needed */
/* Fsync if needed */
now
=
time
(
NULL
);
now
=
time
(
NULL
);
if
(
server
.
appendfsync
==
APPENDFSYNC_ALWAYS
||
if
(
server
.
appendfsync
==
APPENDFSYNC_ALWAYS
||
...
@@ -8704,7 +8716,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -8704,7 +8716,7 @@ static int rewriteAppendOnlyFile(char *filename) {
/* Make sure data will not remain on the OS's output buffers */
/* Make sure data will not remain on the OS's output buffers */
fflush
(
fp
);
fflush
(
fp
);
fsync
(
fileno
(
fp
));
aof_
fsync
(
fileno
(
fp
));
fclose
(
fp
);
fclose
(
fp
);
/* Use RENAME to make sure the DB file is changed atomically only
/* Use RENAME to make sure the DB file is changed atomically only
...
@@ -8821,7 +8833,7 @@ static void aofRemoveTempFile(pid_t childpid) {
...
@@ -8821,7 +8833,7 @@ static void aofRemoveTempFile(pid_t childpid) {
* at runtime using the CONFIG command. */
* at runtime using the CONFIG command. */
static
void
stopAppendOnly
(
void
)
{
static
void
stopAppendOnly
(
void
)
{
flushAppendOnlyFile
();
flushAppendOnlyFile
();
fsync
(
server
.
appendfd
);
aof_
fsync
(
server
.
appendfd
);
close
(
server
.
appendfd
);
close
(
server
.
appendfd
);
server
.
appendfd
=
-
1
;
server
.
appendfd
=
-
1
;
...
@@ -9990,6 +10002,11 @@ static void configSetCommand(redisClient *c) {
...
@@ -9990,6 +10002,11 @@ static void configSetCommand(redisClient *c) {
}
else
{
}
else
{
goto
badfmt
;
goto
badfmt
;
}
}
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"no-appendfsync-on-rewrite"
))
{
int
yn
=
yesnotoi
(
o
->
ptr
);
if
(
yn
==
-
1
)
goto
badfmt
;
server
.
no_appendfsync_on_rewrite
=
yn
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"appendonly"
))
{
}
else
if
(
!
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"appendonly"
))
{
int
old
=
server
.
appendonly
;
int
old
=
server
.
appendonly
;
int
new
=
yesnotoi
(
o
->
ptr
);
int
new
=
yesnotoi
(
o
->
ptr
);
...
@@ -10105,6 +10122,11 @@ static void configGetCommand(redisClient *c) {
...
@@ -10105,6 +10122,11 @@ static void configGetCommand(redisClient *c) {
addReplyBulkCString
(
c
,
server
.
appendonly
?
"yes"
:
"no"
);
addReplyBulkCString
(
c
,
server
.
appendonly
?
"yes"
:
"no"
);
matches
++
;
matches
++
;
}
}
if
(
stringmatch
(
pattern
,
"no-appendfsync-on-rewrite"
,
0
))
{
addReplyBulkCString
(
c
,
"no-appendfsync-on-rewrite"
);
addReplyBulkCString
(
c
,
server
.
no_appendfsync_on_rewrite
?
"yes"
:
"no"
);
matches
++
;
}
if
(
stringmatch
(
pattern
,
"appendfsync"
,
0
))
{
if
(
stringmatch
(
pattern
,
"appendfsync"
,
0
))
{
char
*
policy
;
char
*
policy
;
...
...
redis.conf
View file @
752203d8
...
@@ -195,6 +195,26 @@ appendonly no
...
@@ -195,6 +195,26 @@ appendonly no
appendfsync
everysec
appendfsync
everysec
# appendfsync no
# appendfsync no
# When the AOF fsync policy is set to always or everysec, and a background
# saving process (a background save or AOF log background rewriting) is
# performing a lot of I/O against the disk, in some Linux configurations
# Redis may block too long on the fsync() call. Note that there is no fix for
# this currently, as even performing fsync in a different thread will block
# our synchronous write(2) call.
#
# In order to mitigate this problem it's possible to use the following option
# that will prevent fsync() from being called in the main process while a
# BGSAVE or BGREWRITEAOF is in progress.
#
# This means that while another child is saving the durability of Redis is
# the same as "appendfsync none", that in pratical terms means that it is
# possible to lost up to 30 seconds of log in the worst scenario (with the
# default Linux settings).
#
# If you have latency problems turn this to "yes". Otherwise leave it as
# "no" that is the safest pick from the point of view of durability.
no
-
appendfsync
-
on
-
rewrite
no
################################ VIRTUAL MEMORY ###############################
################################ VIRTUAL MEMORY ###############################
# Virtual Memory allows Redis to work with datasets bigger than the actual
# Virtual Memory allows Redis to work with datasets bigger than the actual
...
...
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