Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
9cf500a3
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
9cf500a3
编写于
4月 14, 2020
作者:
S
ShooterIT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implements sendfile for redis.
上级
7428f512
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
55 addition
and
2 deletion
+55
-2
src/config.h
src/config.h
+6
-0
src/replication.c
src/replication.c
+49
-2
未找到文件。
src/config.h
浏览文件 @
9cf500a3
...
...
@@ -133,6 +133,12 @@ void setproctitle(const char *fmt, ...);
/* Byte ordering detection */
#include <sys/types.h>
/* This will likely define BYTE_ORDER */
/* Define redis_sendfile. */
#if defined(__linux__) || (defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_5))
#define HAVE_SENDFILE 1
ssize_t
redis_sendfile
(
int
out_fd
,
int
in_fd
,
off_t
offset
,
size_t
count
);
#endif
#ifndef BYTE_ORDER
#if (BSD >= 199103)
# include <machine/endian.h>
...
...
src/replication.c
浏览文件 @
9cf500a3
...
...
@@ -972,10 +972,41 @@ void removeRDBUsedToSyncReplicas(void) {
}
}
#if HAVE_SENDFILE
/* Implements redis_sendfile to transfer data between file descriptors and
* avoid transferring data to and from user space.
*
* The function prototype is just like sendfile(2) on Linux. in_fd is a file
* descriptor opened for reading and out_fd is a descriptor opened for writing.
* offset specifies where to start reading data from in_fd. count is the number
* of bytes to copy between the file descriptors.
*
* The return value is the number of bytes written to out_fd, if the transfer
* was successful. On error, -1 is returned, and errno is set appropriately. */
ssize_t
redis_sendfile
(
int
out_fd
,
int
in_fd
,
off_t
offset
,
size_t
count
)
{
#if defined(__linux__)
#include <sys/sendfile.h>
return
sendfile
(
out_fd
,
in_fd
,
&
offset
,
count
);
#elif defined(__APPLE__)
off_t
len
=
count
;
/* Notice that it may return -1 and errno is set to EAGAIN even if some
* bytes have been sent successfully and the len argument is set correctly
* when using a socket marked for non-blocking I/O. */
if
(
sendfile
(
in_fd
,
out_fd
,
offset
,
&
len
,
NULL
,
0
)
==
-
1
&&
errno
!=
EAGAIN
)
return
-
1
;
else
return
(
ssize_t
)
len
;
#endif
errno
=
ENOSYS
;
return
-
1
;
}
#endif
void
sendBulkToSlave
(
connection
*
conn
)
{
client
*
slave
=
connGetPrivateData
(
conn
);
char
buf
[
PROTO_IOBUF_LEN
];
ssize_t
nwritten
,
buflen
;
ssize_t
nwritten
;
/* Before sending the RDB file, we send the preamble as configured by the
* replication process. Currently the preamble is just the bulk count of
...
...
@@ -1001,6 +1032,21 @@ void sendBulkToSlave(connection *conn) {
}
/* If the preamble was already transferred, send the RDB bulk data. */
#if HAVE_SENDFILE
if
((
nwritten
=
redis_sendfile
(
conn
->
fd
,
slave
->
repldbfd
,
slave
->
repldboff
,
PROTO_IOBUF_LEN
))
==
-
1
)
{
if
(
errno
!=
EAGAIN
)
{
serverLog
(
LL_WARNING
,
"Sendfile error sending DB to replica: %s"
,
strerror
(
errno
));
freeClient
(
slave
);
}
return
;
}
#else
ssize_t
buflen
;
char
buf
[
PROTO_IOBUF_LEN
];
lseek
(
slave
->
repldbfd
,
slave
->
repldboff
,
SEEK_SET
);
buflen
=
read
(
slave
->
repldbfd
,
buf
,
PROTO_IOBUF_LEN
);
if
(
buflen
<=
0
)
{
...
...
@@ -1017,6 +1063,7 @@ void sendBulkToSlave(connection *conn) {
}
return
;
}
#endif
slave
->
repldboff
+=
nwritten
;
server
.
stat_net_output_bytes
+=
nwritten
;
if
(
slave
->
repldboff
==
slave
->
repldbsize
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录