Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
c6b1252f
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c6b1252f
编写于
4月 29, 2019
作者:
Z
zhaozhao.zz
提交者:
antirez
5月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aof: enhance AOF_FSYNC_EVERYSEC, more details in #5985
上级
ce54e299
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
3 deletion
+32
-3
src/aof.c
src/aof.c
+31
-3
src/server.h
src/server.h
+1
-0
未找到文件。
src/aof.c
浏览文件 @
c6b1252f
...
...
@@ -197,6 +197,12 @@ ssize_t aofRewriteBufferWrite(int fd) {
* 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
* file descriptor (the one of the AOF file) in another thread. */
void
aof_background_fsync
(
int
fd
)
{
...
...
@@ -333,10 +339,24 @@ void flushAppendOnlyFile(int force) {
int
sync_in_progress
=
0
;
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
)
sync_in_progress
=
bioPendingJobsOfType
(
BIO_AOF_FSYNC
)
!=
0
;
sync_in_progress
=
aofFsyncInProgress
()
;
if
(
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
!
force
)
{
/* With this append fsync policy we do background fsyncing.
...
...
@@ -468,6 +488,7 @@ void flushAppendOnlyFile(int force) {
server
.
aof_buf
=
sdsempty
();
}
try_fsync:
/* Don't fsync if no-appendfsync-on-rewrite is set to yes and there are
* children doing I/O in the background. */
if
(
server
.
aof_no_fsync_on_rewrite
&&
...
...
@@ -482,10 +503,14 @@ void flushAppendOnlyFile(int force) {
redis_fsync
(
server
.
aof_fd
);
/* Let's try to get this data on the disk */
latencyEndMonitor
(
latency
);
latencyAddSampleIfNeeded
(
"aof-fsync-always"
,
latency
);
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
server
.
aof_last_fsync
=
server
.
unixtime
;
}
else
if
((
server
.
aof_fsync
==
AOF_FSYNC_EVERYSEC
&&
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
;
}
}
...
...
@@ -690,6 +715,7 @@ int loadAppendOnlyFile(char *filename) {
* operation is received. */
if
(
fp
&&
redis_fstat
(
fileno
(
fp
),
&
sb
)
!=
-
1
&&
sb
.
st_size
==
0
)
{
server
.
aof_current_size
=
0
;
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
fclose
(
fp
);
return
C_ERR
;
}
...
...
@@ -828,6 +854,7 @@ loaded_ok: /* DB loaded, cleanup and return C_OK to the caller. */
stopLoading
();
aofUpdateCurrentSize
();
server
.
aof_rewrite_base_size
=
server
.
aof_current_size
;
server
.
aof_fsync_offset
=
server
.
aof_current_size
;
return
C_OK
;
readerr:
/* Read error. If feof(fp) is true, fall through to unexpected EOF. */
...
...
@@ -1734,6 +1761,7 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) {
server
.
aof_selected_db
=
-
1
;
/* Make sure SELECT is re-issued */
aofUpdateCurrentSize
();
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
* the new AOF from the background rewrite buffer. */
...
...
src/server.h
浏览文件 @
c6b1252f
...
...
@@ -1063,6 +1063,7 @@ struct redisServer {
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_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. */
pid_t
aof_child_pid
;
/* PID if rewriting process */
list
*
aof_rewrite_buf_blocks
;
/* Hold changes during an AOF rewrite. */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录