Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
89f82a25
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,发现更多精彩内容 >>
提交
89f82a25
编写于
10月 16, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Diskless replication: EOF:<mark> streaming support slave side.
上级
583a762c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
7 deletion
+60
-7
src/replication.c
src/replication.c
+60
-7
未找到文件。
src/replication.c
浏览文件 @
89f82a25
...
...
@@ -812,6 +812,12 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
REDIS_NOTUSED
(
privdata
);
REDIS_NOTUSED
(
mask
);
/* Static vars used to hold the EOF mark, and the last bytes received
* form the server: when they match, we reached the end of the transfer. */
static
char
eofmark
[
REDIS_RUN_ID_SIZE
];
static
char
lastbytes
[
REDIS_RUN_ID_SIZE
];
static
int
usemark
=
0
;
/* If repl_transfer_size == -1 we still have to read the bulk length
* from the master reply. */
if
(
server
.
repl_transfer_size
==
-
1
)
{
...
...
@@ -837,16 +843,41 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
redisLog
(
REDIS_WARNING
,
"Bad protocol from MASTER, the first byte is not '$' (we received '%s'), are you sure the host and port are right?"
,
buf
);
goto
error
;
}
server
.
repl_transfer_size
=
strtol
(
buf
+
1
,
NULL
,
10
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: receiving %lld bytes from master"
,
(
long
long
)
server
.
repl_transfer_size
);
/* There are two possible forms for the bulk payload. One is the
* usual $<count> bulk format. The other is used for diskless transfers
* when the master does not know beforehand the size of the file to
* transfer. In the latter case, the following format is used:
*
* $EOF:<40 bytes delimiter>
*
* At the end of the file the announced delimiter is transmitted. The
* delimiter is long and random enough that the probability of a
* collision with the actual file content can be ignored. */
if
(
strncmp
(
buf
+
1
,
"EOF:"
,
4
)
==
0
&&
strlen
(
buf
+
5
)
>=
REDIS_RUN_ID_SIZE
)
{
usemark
=
1
;
memcpy
(
eofmark
,
buf
+
5
,
REDIS_RUN_ID_SIZE
);
memset
(
lastbytes
,
0
,
REDIS_RUN_ID_SIZE
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: receiving streamed RDB from master"
);
}
else
{
usemark
=
0
;
server
.
repl_transfer_size
=
strtol
(
buf
+
1
,
NULL
,
10
);
redisLog
(
REDIS_NOTICE
,
"MASTER <-> SLAVE sync: receiving %lld bytes from master"
,
(
long
long
)
server
.
repl_transfer_size
);
}
return
;
}
/* Read bulk data */
left
=
server
.
repl_transfer_size
-
server
.
repl_transfer_read
;
readlen
=
(
left
<
(
signed
)
sizeof
(
buf
))
?
left
:
(
signed
)
sizeof
(
buf
);
if
(
usemark
)
{
left
=
server
.
repl_transfer_size
-
server
.
repl_transfer_read
;
readlen
=
(
left
<
(
signed
)
sizeof
(
buf
))
?
left
:
(
signed
)
sizeof
(
buf
);
}
else
{
readlen
=
sizeof
(
buf
);
}
nread
=
read
(
fd
,
buf
,
readlen
);
if
(
nread
<=
0
)
{
redisLog
(
REDIS_WARNING
,
"I/O error trying to sync with MASTER: %s"
,
...
...
@@ -854,6 +885,23 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
replicationAbortSyncTransfer
();
return
;
}
/* When a mark is used, we want to detect EOF asap in order to avoid
* writing the EOF mark into the file... */
int
eof_reached
=
0
;
if
(
usemark
)
{
/* Update the last bytes array, and check if it matches our delimiter. */
if
(
nread
>=
REDIS_RUN_ID_SIZE
)
{
memcpy
(
lastbytes
,
buf
+
nread
-
REDIS_RUN_ID_SIZE
,
REDIS_RUN_ID_SIZE
);
}
else
{
int
rem
=
REDIS_RUN_ID_SIZE
-
nread
;
memmove
(
lastbytes
,
lastbytes
+
nread
,
rem
);
memcpy
(
lastbytes
+
rem
,
buf
,
nread
);
}
if
(
memcmp
(
lastbytes
,
eofmark
,
REDIS_RUN_ID_SIZE
)
==
0
)
eof_reached
=
1
;
}
server
.
repl_transfer_lastio
=
server
.
unixtime
;
if
(
write
(
server
.
repl_transfer_fd
,
buf
,
nread
)
!=
nread
)
{
redisLog
(
REDIS_WARNING
,
"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchronization: %s"
,
strerror
(
errno
));
...
...
@@ -875,7 +923,12 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
}
/* Check if the transfer is now complete */
if
(
server
.
repl_transfer_read
==
server
.
repl_transfer_size
)
{
if
(
!
usemark
)
{
if
(
server
.
repl_transfer_read
==
server
.
repl_transfer_size
)
eof_reached
=
1
;
}
if
(
eof_reached
)
{
if
(
rename
(
server
.
repl_transfer_tmpfile
,
server
.
rdb_filename
)
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s"
,
strerror
(
errno
));
replicationAbortSyncTransfer
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录