Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
5e2319c3
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,发现更多精彩内容 >>
提交
5e2319c3
编写于
3月 03, 2020
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove RDB files used for replication in persistence-less instances.
上级
6dd8de17
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
1 deletion
+56
-1
src/replication.c
src/replication.c
+47
-1
src/server.c
src/server.c
+8
-0
src/server.h
src/server.h
+1
-0
未找到文件。
src/replication.c
浏览文件 @
5e2319c3
...
...
@@ -45,6 +45,11 @@ void replicationSendAck(void);
void
putSlaveOnline
(
client
*
slave
);
int
cancelReplicationHandshake
(
void
);
/* We take a global flag to remember if this instance generated an RDB
* because of replication, so that we can remove the RDB file in case
* the instance is configured to have no persistence. */
int
RDBGeneratedByReplication
=
0
;
/* --------------------------- Utility functions ---------------------------- */
/* Return the pointer to a string representing the slave ip:listening_port
...
...
@@ -591,6 +596,10 @@ int startBgsaveForReplication(int mincapa) {
retval
=
C_ERR
;
}
/* If we succeeded to start a BGSAVE with disk target, let's remember
* this fact, so that we can later delete the file if needed. */
if
(
retval
==
C_OK
&&
!
socket_target
)
RDBGeneratedByReplication
=
1
;
/* If we failed to BGSAVE, remove the slaves waiting for a full
* resynchronization from the list of slaves, inform them with
* an error about what happened, close the connection ASAP. */
...
...
@@ -883,6 +892,36 @@ void putSlaveOnline(client *slave) {
replicationGetSlaveName
(
slave
));
}
/* We call this function periodically to remove an RDB file that was
* generated because of replication, in an instance that is otherwise
* without any persistence. We don't want instances without persistence
* to take RDB files around, this violates certain policies in certain
* environments. */
void
removeRDBUsedToSyncReplicas
(
void
)
{
if
(
allPersistenceDisabled
()
&&
RDBGeneratedByReplication
)
{
client
*
slave
;
listNode
*
ln
;
listIter
li
;
int
delrdb
=
1
;
listRewind
(
server
.
slaves
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
slave
=
ln
->
value
;
if
(
slave
->
replstate
==
SLAVE_STATE_WAIT_BGSAVE_START
||
slave
->
replstate
==
SLAVE_STATE_WAIT_BGSAVE_END
||
slave
->
replstate
==
SLAVE_STATE_SEND_BULK
)
{
delrdb
=
0
;
break
;
/* No need to check the other replicas. */
}
}
if
(
delrdb
)
{
RDBGeneratedByReplication
=
0
;
unlink
(
server
.
rdb_filename
);
}
}
}
void
sendBulkToSlave
(
connection
*
conn
)
{
client
*
slave
=
connGetPrivateData
(
conn
);
char
buf
[
PROTO_IOBUF_LEN
];
...
...
@@ -894,7 +933,8 @@ void sendBulkToSlave(connection *conn) {
if
(
slave
->
replpreamble
)
{
nwritten
=
connWrite
(
conn
,
slave
->
replpreamble
,
sdslen
(
slave
->
replpreamble
));
if
(
nwritten
==
-
1
)
{
serverLog
(
LL_VERBOSE
,
"Write error sending RDB preamble to replica: %s"
,
serverLog
(
LL_VERBOSE
,
"Write error sending RDB preamble to replica: %s"
,
connGetLastError
(
conn
));
freeClient
(
slave
);
return
;
...
...
@@ -1639,12 +1679,14 @@ void readSyncBulkPayload(connection *conn) {
"Failed trying to load the MASTER synchronization "
"DB from disk"
);
cancelReplicationHandshake
();
if
(
allPersistenceDisabled
())
unlink
(
server
.
rdb_filename
);
/* Note that there's no point in restarting the AOF on sync failure,
it'll be restarted when sync succeeds or replica promoted. */
return
;
}
/* Cleanup. */
if
(
allPersistenceDisabled
())
unlink
(
server
.
rdb_filename
);
zfree
(
server
.
repl_transfer_tmpfile
);
close
(
server
.
repl_transfer_fd
);
server
.
repl_transfer_fd
=
-
1
;
...
...
@@ -3149,6 +3191,10 @@ void replicationCron(void) {
}
}
/* Remove the RDB file used for replication if Redis is not running
* with any persistence. */
removeRDBUsedToSyncReplicas
();
/* Refresh the number of slaves with lag <= min-slaves-max-lag. */
refreshGoodSlavesCount
();
replication_cron_loops
++
;
/* Incremented with frequency 1 HZ. */
...
...
src/server.c
浏览文件 @
5e2319c3
...
...
@@ -1455,12 +1455,20 @@ void updateDictResizePolicy(void) {
dictDisableResize
();
}
/* Return true if there are no active children processes doing RDB saving,
* AOF rewriting, or some side process spawned by a loaded module. */
int
hasActiveChildProcess
()
{
return
server
.
rdb_child_pid
!=
-
1
||
server
.
aof_child_pid
!=
-
1
||
server
.
module_child_pid
!=
-
1
;
}
/* Return true if this instance has persistence completely turned off:
* both RDB and AOF are disabled. */
int
allPersistenceDisabled
(
void
)
{
return
server
.
saveparamslen
==
0
&&
server
.
aof_state
==
AOF_OFF
;
}
/* ======================= Cron: called every 100 ms ======================== */
/* Add a sample to the operations per second array of samples. */
...
...
src/server.h
浏览文件 @
5e2319c3
...
...
@@ -1786,6 +1786,7 @@ void loadingProgress(off_t pos);
void
stopLoading
(
int
success
);
void
startSaving
(
int
rdbflags
);
void
stopSaving
(
int
success
);
int
allPersistenceDisabled
(
void
);
#define DISK_ERROR_TYPE_AOF 1
/* Don't accept writes: AOF errors. */
#define DISK_ERROR_TYPE_RDB 2
/* Don't accept writes: RDB errors. */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录