Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
9f6f436a
R
redis
项目概览
hanoi2005
/
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,发现更多精彩内容 >>
提交
9f6f436a
编写于
12月 12, 2012
作者:
Y
yoav
提交者:
antirez
7月 16, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Chunked loading of RDB to prevent redis from stalling reading very large keys.
上级
112e7636
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
45 addition
and
15 deletion
+45
-15
src/rdb.c
src/rdb.c
+14
-9
src/redis.c
src/redis.c
+1
-0
src/redis.h
src/redis.h
+1
-0
src/rio.c
src/rio.c
+4
-0
src/rio.h
src/rio.h
+25
-6
未找到文件。
src/rdb.c
浏览文件 @
9f6f436a
...
...
@@ -1057,21 +1057,32 @@ void stopLoading(void) {
server
.
loading
=
0
;
}
/* Track loading progress in order to serve client's from time to time
and if needed calculate rdb checksum */
void
rdbLoadProgressCallback
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
if
(
server
.
rdb_checksum
)
rioGenericUpdateChecksum
(
r
,
buf
,
len
);
if
(
server
.
loading_process_events_interval_bytes
&&
(
r
->
processed_bytes
+
len
)
/
server
.
loading_process_events_interval_bytes
>
r
->
processed_bytes
/
server
.
loading_process_events_interval_bytes
)
{
loadingProgress
(
r
->
processed_bytes
);
aeProcessEvents
(
server
.
el
,
AE_FILE_EVENTS
|
AE_DONT_WAIT
);
}
}
int
rdbLoad
(
char
*
filename
)
{
uint32_t
dbid
;
int
type
,
rdbver
;
redisDb
*
db
=
server
.
db
+
0
;
char
buf
[
1024
];
long
long
expiretime
,
now
=
mstime
();
long
loops
=
0
;
FILE
*
fp
;
rio
rdb
;
if
((
fp
=
fopen
(
filename
,
"r"
))
==
NULL
)
return
REDIS_ERR
;
rioInitWithFile
(
&
rdb
,
fp
);
if
(
server
.
rdb_checksum
)
rdb
.
update_cksum
=
rioGenericUpdateChecksum
;
rdb
.
update_cksum
=
rdbLoadProgressCallback
;
rdb
.
max_processing_chunk
=
server
.
loading_process_events_interval_bytes
;
if
(
rioRead
(
&
rdb
,
buf
,
9
)
==
0
)
goto
eoferr
;
buf
[
9
]
=
'\0'
;
if
(
memcmp
(
buf
,
"REDIS"
,
5
)
!=
0
)
{
...
...
@@ -1093,12 +1104,6 @@ int rdbLoad(char *filename) {
robj
*
key
,
*
val
;
expiretime
=
-
1
;
/* Serve the clients from time to time */
if
(
!
(
loops
++
%
1000
))
{
loadingProgress
(
rioTell
(
&
rdb
));
aeProcessEvents
(
server
.
el
,
AE_FILE_EVENTS
|
AE_DONT_WAIT
);
}
/* Read type. */
if
((
type
=
rdbLoadType
(
&
rdb
))
==
-
1
)
goto
eoferr
;
if
(
type
==
REDIS_RDB_OPCODE_EXPIRETIME
)
{
...
...
src/redis.c
浏览文件 @
9f6f436a
...
...
@@ -1250,6 +1250,7 @@ void initServerConfig() {
server
.
lua_time_limit
=
REDIS_LUA_TIME_LIMIT
;
server
.
lua_client
=
NULL
;
server
.
lua_timedout
=
0
;
server
.
loading_process_events_interval_bytes
=
(
1024
*
1024
*
2
);
updateLRUClock
();
resetServerSaveParams
();
...
...
src/redis.h
浏览文件 @
9f6f436a
...
...
@@ -596,6 +596,7 @@ struct redisServer {
off_t
loading_total_bytes
;
off_t
loading_loaded_bytes
;
time_t
loading_start_time
;
off_t
loading_process_events_interval_bytes
;
/* Fast pointers to often looked up command */
struct
redisCommand
*
delCommand
,
*
multiCommand
,
*
lpushCommand
,
*
lpopCommand
,
*
rpopCommand
;
...
...
src/rio.c
浏览文件 @
9f6f436a
...
...
@@ -108,6 +108,8 @@ static const rio rioBufferIO = {
rioBufferTell
,
NULL
,
/* update_checksum */
0
,
/* current checksum */
0
,
/* bytes read or written */
0
,
/* read/write chunk size */
{
{
NULL
,
0
}
}
/* union for io-specific vars */
};
...
...
@@ -117,6 +119,8 @@ static const rio rioFileIO = {
rioFileTell
,
NULL
,
/* update_checksum */
0
,
/* current checksum */
0
,
/* bytes read or written */
0
,
/* read/write chunk size */
{
{
NULL
,
0
}
}
/* union for io-specific vars */
};
...
...
src/rio.h
浏览文件 @
9f6f436a
...
...
@@ -53,6 +53,12 @@ struct _rio {
/* The current checksum */
uint64_t
cksum
;
/* number of bytes read or written */
size_t
processed_bytes
;
/* maximum simgle read or write chunk size */
size_t
max_processing_chunk
;
/* Backend-specific vars. */
union
{
struct
{
...
...
@@ -74,16 +80,29 @@ typedef struct _rio rio;
* if needed. */
static
inline
size_t
rioWrite
(
rio
*
r
,
const
void
*
buf
,
size_t
len
)
{
if
(
r
->
update_cksum
)
r
->
update_cksum
(
r
,
buf
,
len
);
return
r
->
write
(
r
,
buf
,
len
);
while
(
len
)
{
size_t
bytes_to_write
=
(
r
->
max_processing_chunk
&&
r
->
max_processing_chunk
<
len
)
?
r
->
max_processing_chunk
:
len
;
if
(
r
->
update_cksum
)
r
->
update_cksum
(
r
,
buf
,
bytes_to_write
);
if
(
r
->
write
(
r
,
buf
,
bytes_to_write
)
==
0
)
return
0
;
buf
=
(
char
*
)
buf
+
bytes_to_write
;
len
-=
bytes_to_write
;
r
->
processed_bytes
+=
bytes_to_write
;
}
return
1
;
}
static
inline
size_t
rioRead
(
rio
*
r
,
void
*
buf
,
size_t
len
)
{
if
(
r
->
read
(
r
,
buf
,
len
)
==
1
)
{
if
(
r
->
update_cksum
)
r
->
update_cksum
(
r
,
buf
,
len
);
return
1
;
while
(
len
)
{
size_t
bytes_to_read
=
(
r
->
max_processing_chunk
&&
r
->
max_processing_chunk
<
len
)
?
r
->
max_processing_chunk
:
len
;
if
(
r
->
read
(
r
,
buf
,
bytes_to_read
)
==
0
)
return
0
;
if
(
r
->
update_cksum
)
r
->
update_cksum
(
r
,
buf
,
bytes_to_read
);
buf
=
(
char
*
)
buf
+
bytes_to_read
;
len
-=
bytes_to_read
;
r
->
processed_bytes
+=
bytes_to_read
;
}
return
0
;
return
1
;
}
static
inline
off_t
rioTell
(
rio
*
r
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录