Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
82bfae5b
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,发现更多精彩内容 >>
提交
82bfae5b
编写于
10月 15, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Diskless replication: handle putting the slave online.
上级
132c108f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
57 addition
and
31 deletion
+57
-31
src/replication.c
src/replication.c
+57
-31
未找到文件。
src/replication.c
浏览文件 @
82bfae5b
...
...
@@ -605,6 +605,29 @@ void replconfCommand(redisClient *c) {
addReply
(
c
,
shared
.
ok
);
}
/* This function puts a slave in the online state, and should be called just
* after a slave received the RDB file for the initial synchronization, and
* we are finally ready to send the incremental stream of commands.
*
* It does a few things:
*
* 1) Put the slave in ONLINE state.
* 2) Make sure the writable event is re-installed, since calling the SYNC
* command disables it, so that we can accumulate output buffer without
* sending it to the slave.
* 3) Update the count of good slaves. */
void
putSlaveOnline
(
redisClient
*
slave
)
{
slave
->
replstate
=
REDIS_REPL_ONLINE
;
slave
->
repl_ack_time
=
server
.
unixtime
;
if
(
aeCreateFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
,
sendReplyToClient
,
slave
)
==
AE_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Unable to register writable event for slave bulk transfer: %s"
,
strerror
(
errno
));
freeClient
(
slave
);
return
;
}
refreshGoodSlavesCount
();
}
void
sendBulkToSlave
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
redisClient
*
slave
=
privdata
;
REDIS_NOTUSED
(
el
);
...
...
@@ -655,16 +678,8 @@ void sendBulkToSlave(aeEventLoop *el, int fd, void *privdata, int mask) {
close
(
slave
->
repldbfd
);
slave
->
repldbfd
=
-
1
;
aeDeleteFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
);
slave
->
replstate
=
REDIS_REPL_ONLINE
;
slave
->
repl_ack_time
=
server
.
unixtime
;
if
(
aeCreateFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
,
sendReplyToClient
,
slave
)
==
AE_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Unable to register writable event for slave bulk transfer: %s"
,
strerror
(
errno
));
freeClient
(
slave
);
return
;
}
refreshGoodSlavesCount
();
redisLog
(
REDIS_NOTICE
,
"Synchronization with slave succeeded"
);
putSlaveOnline
(
slave
);
redisLog
(
REDIS_NOTICE
,
"Synchronization with slave succeeded (disk)"
);
}
}
...
...
@@ -694,27 +709,38 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
}
else
if
(
slave
->
replstate
==
REDIS_REPL_WAIT_BGSAVE_END
)
{
struct
redis_stat
buf
;
if
(
bgsaveerr
!=
REDIS_OK
)
{
freeClient
(
slave
);
redisLog
(
REDIS_WARNING
,
"SYNC failed. BGSAVE child returned an error"
);
continue
;
}
if
((
slave
->
repldbfd
=
open
(
server
.
rdb_filename
,
O_RDONLY
))
==
-
1
||
redis_fstat
(
slave
->
repldbfd
,
&
buf
)
==
-
1
)
{
freeClient
(
slave
);
redisLog
(
REDIS_WARNING
,
"SYNC failed. Can't open/stat DB after BGSAVE: %s"
,
strerror
(
errno
));
continue
;
}
slave
->
repldboff
=
0
;
slave
->
repldbsize
=
buf
.
st_size
;
slave
->
replstate
=
REDIS_REPL_SEND_BULK
;
slave
->
replpreamble
=
sdscatprintf
(
sdsempty
(),
"$%lld
\r\n
"
,
(
unsigned
long
long
)
slave
->
repldbsize
);
aeDeleteFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
);
if
(
aeCreateFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
,
sendBulkToSlave
,
slave
)
==
AE_ERR
)
{
freeClient
(
slave
);
continue
;
/* If this was an RDB on disk save, we have to prepare to send
* the RDB from disk to the slave socket. Otherwise if this was
* already an RDB -> Slaves socket transfer, used in the case of
* diskless replication, our work is trivial, we can just put
* the slave online. */
if
(
type
==
REDIS_RDB_CHILD_TYPE_SOCKET
)
{
putSlaveOnline
(
slave
);
redisLog
(
REDIS_NOTICE
,
"Synchronization with slave succeeded (socket)"
);
}
else
{
if
(
bgsaveerr
!=
REDIS_OK
)
{
freeClient
(
slave
);
redisLog
(
REDIS_WARNING
,
"SYNC failed. BGSAVE child returned an error"
);
continue
;
}
if
((
slave
->
repldbfd
=
open
(
server
.
rdb_filename
,
O_RDONLY
))
==
-
1
||
redis_fstat
(
slave
->
repldbfd
,
&
buf
)
==
-
1
)
{
freeClient
(
slave
);
redisLog
(
REDIS_WARNING
,
"SYNC failed. Can't open/stat DB after BGSAVE: %s"
,
strerror
(
errno
));
continue
;
}
slave
->
repldboff
=
0
;
slave
->
repldbsize
=
buf
.
st_size
;
slave
->
replstate
=
REDIS_REPL_SEND_BULK
;
slave
->
replpreamble
=
sdscatprintf
(
sdsempty
(),
"$%lld
\r\n
"
,
(
unsigned
long
long
)
slave
->
repldbsize
);
aeDeleteFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
);
if
(
aeCreateFileEvent
(
server
.
el
,
slave
->
fd
,
AE_WRITABLE
,
sendBulkToSlave
,
slave
)
==
AE_ERR
)
{
freeClient
(
slave
);
continue
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录