Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
e82ec2c5
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
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,发现更多精彩内容 >>
提交
e82ec2c5
编写于
10月 15, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Diskless replication: child writes report to parent.
上级
2ed67e4a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
0 deletion
+40
-0
src/rdb.c
src/rdb.c
+40
-0
未找到文件。
src/rdb.c
浏览文件 @
e82ec2c5
...
...
@@ -1328,6 +1328,7 @@ void backgroundSaveDoneHandler(int exitcode, int bysignal) {
* that are currently in REDIS_REPL_WAIT_BGSAVE_START state. */
int
rdbSaveToSlavesSockets
(
void
)
{
int
*
fds
;
uint64_t
*
clientids
;
int
numfds
;
listNode
*
ln
;
listIter
li
;
...
...
@@ -1347,6 +1348,10 @@ int rdbSaveToSlavesSockets(void) {
/* Collect the file descriptors of the slaves we want to transfer
* the RDB to, which are i WAIT_BGSAVE_START state. */
fds
=
zmalloc
(
sizeof
(
int
)
*
listLength
(
server
.
slaves
));
/* We also allocate an array of corresponding client IDs. This will
* be useful for the child process in order to build the report
* (sent via unix pipe) that will be sent to the parent. */
clientids
=
zmalloc
(
sizeof
(
uint64_t
)
*
listLength
(
server
.
slaves
));
numfds
=
0
;
listRewind
(
server
.
slaves
,
&
li
);
...
...
@@ -1354,6 +1359,7 @@ int rdbSaveToSlavesSockets(void) {
redisClient
*
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_START
)
{
clientids
[
numfds
]
=
slave
->
id
;
fds
[
numfds
++
]
=
slave
->
fd
;
slave
->
replstate
=
REDIS_REPL_WAIT_BGSAVE_END
;
}
...
...
@@ -1381,10 +1387,44 @@ int rdbSaveToSlavesSockets(void) {
"RDB: %zu MB of memory used by copy-on-write"
,
private_dirty
/
(
1024
*
1024
));
}
/* If we are returning OK, at least one slave was served
* with the RDB file as expected, so we need to send a report
* to the parent via the pipe. The format of the message is:
* just an array of uint64_t integers (to avoid alignment concerns),
* where the first element is the number of uint64_t elements
* that follows, representing slave client IDs that were
* successfully served. */
void
*
msg
=
zmalloc
(
sizeof
(
uint64_t
)
*
(
1
+
numfds
));
uint64_t
*
len
=
msg
;
uint64_t
*
ids
=
len
+
1
;
int
j
,
msglen
;
*
len
=
0
;
for
(
j
=
0
;
j
<
numfds
;
j
++
)
{
/* No error? Add it. */
if
(
slave_sockets
.
io
.
fdset
.
state
[
j
]
==
0
)
{
ids
[
*
len
]
=
clientids
[
j
];
(
*
len
)
++
;
}
}
/* Write the message to the parent. If we have no good slaves or
* we are unable to transfer the message to the parent, we exit
* with an error so that the parent will abort the replication
* process with all the childre that were waiting. */
msglen
=
sizeof
(
uint64_t
)
*
(
1
+
(
*
len
));
if
(
*
len
==
0
||
write
(
server
.
rdb_pipe_write_result_to_parent
,
msg
,
msglen
)
!=
msglen
)
{
retval
=
REDIS_ERR
;
}
}
exitFromChild
((
retval
==
REDIS_OK
)
?
0
:
1
);
}
else
{
/* Parent */
zfree
(
clientids
);
/* Not used by parent. Free ASAP. */
server
.
stat_fork_time
=
ustime
()
-
start
;
server
.
stat_fork_rate
=
(
double
)
zmalloc_used_memory
()
*
1000000
/
server
.
stat_fork_time
/
(
1024
*
1024
*
1024
);
/* GB per second. */
latencyAddSampleIfNeeded
(
"fork"
,
server
.
stat_fork_time
/
1000
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录