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
e633254c
Unverified
Commit
e633254c
authored
May 10, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
May 10, 2019
Browse files
Merge pull request #6053 from soloestoy/enhance-aof-fsync-everysec
aof: enhance AOF_FSYNC_EVERYSEC, more details in #5985
parents
34f6d947
bcac165f
Changes
2
Show whitespace changes
Inline
Side-by-side
src/aof.c
View file @
e633254c
...
@@ -197,6 +197,12 @@ ssize_t aofRewriteBufferWrite(int fd) {
...
@@ -197,6 +197,12 @@ ssize_t aofRewriteBufferWrite(int fd) {
* AOF file implementation
* AOF file implementation
* ------------------------------------------------------------------------- */
* ------------------------------------------------------------------------- */
/* Return true if an AOf fsync is currently already in progress in a
* BIO thread. */
int
aofFsyncInProgress
(
void
)
{
return
bioPendingJobsOfType
(
BIO_AOF_FSYNC
)
!=
0
;
}
/* Starts a background task that performs fsync() against the specified
/* Starts a background task that performs fsync() against the specified
* file descriptor (the one of the AOF file) in another thread. */
* file descriptor (the one of the AOF file) in another thread. */
void
aof_background_fsync
(
int
fd
)
{
void
aof_background_fsync
(
int
fd
)
{
...
@@ -335,10 +341,24 @@ void flushAppendOnlyFile(int force) {
...
@@ -335,10 +341,24 @@ void flushAppendOnlyFile(int force) {
int
sync_in_progress
=
0
;
int
sync_in_progress
=
0
;
mstime_t
latency
;
mstime_t
latency
;
if
(
sdslen
(
server
.
aof_buf
)
==
0
)
return
;
if
(
sdslen
(
server
.
aof_buf
)
==
0
)
{
/* Check if we need to do fsync even the aof buffer is empty,
* because previously in AOF_FSYNC_EVERYSEC mode, fsync is
* called only when aof buffer is not empty, so if users
* stop write commands before fsync called in one second,
* the data in page cache cannot be flushed in time. */
if
(
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
server
.
aof_fsync_offset
!=
server
.
aof_current_size
&&
server
.
unixtime
>
server
.
aof_last_fsync
&&
!
(
sync_in_progress
=
aofFsyncInProgress
()))
{
goto
try_fsync
;
}
else
{
return
;
}
}
if
(
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
)
if
(
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
)
sync_in_progress
=
bioPendingJobsOfType
(
BIO_AOF_FSYNC
)
!=
0
;
sync_in_progress
=
aofFsyncInProgress
()
;
if
(
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
!
force
)
{
if
(
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
!
force
)
{
/* With this append fsync policy we do background fsyncing.
/* With this append fsync policy we do background fsyncing.
...
@@ -470,6 +490,7 @@ void flushAppendOnlyFile(int force) {
...
@@ -470,6 +490,7 @@ void flushAppendOnlyFile(int force) {
server
.
aof_buf
=
sdsempty
();
server
.
aof_buf
=
sdsempty
();
}
}
try_fsync:
/* 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
&&
...
@@ -484,10 +505,14 @@ void flushAppendOnlyFile(int force) {
...
@@ -484,10 +505,14 @@ void flushAppendOnlyFile(int force) {
redis_fsync
(
server
.
aof_fd
);
/* Let's try to get this data on the disk */
redis_fsync
(
server
.
aof_fd
);
/* Let's try to get this data on the disk */
latencyEndMonitor
(
latency
);
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-fsync-always"
,
latency
);
latencyAddSampleIfNeeded
(
"aof-fsync-always"
,
latency
);
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
server
.
aof_last_fsync
=
server
.
unixtime
;
server
.
aof_last_fsync
=
server
.
unixtime
;
}
else
if
((
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
}
else
if
((
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
server
.
unixtime
>
server
.
aof_last_fsync
))
{
server
.
unixtime
>
server
.
aof_last_fsync
))
{
if
(
!
sync_in_progress
)
aof_background_fsync
(
server
.
aof_fd
);
if
(
!
sync_in_progress
)
{
aof_background_fsync
(
server
.
aof_fd
);
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
}
server
.
aof_last_fsync
=
server
.
unixtime
;
server
.
aof_last_fsync
=
server
.
unixtime
;
}
}
}
}
...
@@ -694,6 +719,7 @@ int loadAppendOnlyFile(char *filename) {
...
@@ -694,6 +719,7 @@ int loadAppendOnlyFile(char *filename) {
* operation is received. */
* operation is received. */
if
(
fp
&&
redis_fstat
(
fileno
(
fp
),
&
sb
)
!=
-
1
&&
sb
.
st_size
==
0
)
{
if
(
fp
&&
redis_fstat
(
fileno
(
fp
),
&
sb
)
!=
-
1
&&
sb
.
st_size
==
0
)
{
server
.
aof_current_size
=
0
;
server
.
aof_current_size
=
0
;
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
fclose
(
fp
);
fclose
(
fp
);
return
C_ERR
;
return
C_ERR
;
}
}
...
@@ -832,6 +858,7 @@ loaded_ok: /* DB loaded, cleanup and return C_OK to the caller. */
...
@@ -832,6 +858,7 @@ loaded_ok: /* DB loaded, cleanup and return C_OK to the caller. */
stopLoading
();
stopLoading
();
aofUpdateCurrentSize
();
aofUpdateCurrentSize
();
server
.
aof_rewrite_base_size
=
server
.
aof_current_size
;
server
.
aof_rewrite_base_size
=
server
.
aof_current_size
;
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
return
C_OK
;
return
C_OK
;
readerr:
/* Read error. If feof(fp) is true, fall through to unexpected EOF. */
readerr:
/* Read error. If feof(fp) is true, fall through to unexpected EOF. */
...
@@ -1741,6 +1768,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
...
@@ -1741,6 +1768,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
server
.
aof_selected_db
=
-
1
;
/* Make sure SELECT is re-issued */
server
.
aof_selected_db
=
-
1
;
/* Make sure SELECT is re-issued */
aofUpdateCurrentSize
();
aofUpdateCurrentSize
();
server
.
aof_rewrite_base_size
=
server
.
aof_current_size
;
server
.
aof_rewrite_base_size
=
server
.
aof_current_size
;
server
.
aof_current_size
=
server
.
aof_current_size
;
/* Clear regular AOF buffer since its contents was just written to
/* Clear regular AOF buffer since its contents was just written to
* the new AOF from the background rewrite buffer. */
* the new AOF from the background rewrite buffer. */
...
...
src/server.h
View file @
e633254c
...
@@ -1150,6 +1150,7 @@ struct redisServer {
...
@@ -1150,6 +1150,7 @@ struct redisServer {
off_t
aof_rewrite_min_size
;
/* the AOF file is at least N bytes. */
off_t
aof_rewrite_min_size
;
/* the AOF file is at least N bytes. */
off_t
aof_rewrite_base_size
;
/* AOF size on latest startup or rewrite. */
off_t
aof_rewrite_base_size
;
/* AOF size on latest startup or rewrite. */
off_t
aof_current_size
;
/* AOF current size. */
off_t
aof_current_size
;
/* AOF current size. */
off_t
aof_fsync_offset
;
/* AOF offset which is already synced to disk. */
int
aof_rewrite_scheduled
;
/* Rewrite once BGSAVE terminates. */
int
aof_rewrite_scheduled
;
/* Rewrite once BGSAVE terminates. */
pid_t
aof_child_pid
;
/* PID if rewriting process */
pid_t
aof_child_pid
;
/* PID if rewriting process */
list
*
aof_rewrite_buf_blocks
;
/* Hold changes during an AOF rewrite. */
list
*
aof_rewrite_buf_blocks
;
/* Hold changes during an AOF rewrite. */
...
...
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