Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
82e18077
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,发现更多精彩内容 >>
未验证
提交
82e18077
编写于
3月 18, 2020
作者:
S
Salvatore Sanfilippo
提交者:
GitHub
3月 18, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7001 from trevor211/fixDataInconsistency
Fix data inconsistency
上级
b3a97004
f6029fb9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
96 addition
and
2 deletion
+96
-2
src/rdb.c
src/rdb.c
+1
-1
src/server.c
src/server.c
+6
-1
src/server.h
src/server.h
+2
-0
tests/cluster/tests/14-consistency-check.tcl
tests/cluster/tests/14-consistency-check.tcl
+87
-0
未找到文件。
src/rdb.c
浏览文件 @
82e18077
...
...
@@ -2231,7 +2231,7 @@ int rdbLoadRio(rio *rdb, int rdbflags, rdbSaveInfo *rsi) {
* received from the master. In the latter case, the master is
* responsible for key expiry. If we would expire keys here, the
* snapshot taken by the master may not be reflected on the slave. */
if
(
server
.
masterhost
==
NULL
&&
!
(
rdbflags
&
RDBFLAGS_AOF_PREAMBLE
)
&&
expiretime
!=
-
1
&&
expiretime
<
now
)
{
if
(
iAmMaster
()
&&
!
(
rdbflags
&
RDBFLAGS_AOF_PREAMBLE
)
&&
expiretime
!=
-
1
&&
expiretime
<
now
)
{
decrRefCount
(
key
);
decrRefCount
(
val
);
}
else
{
...
...
src/server.c
浏览文件 @
82e18077
...
...
@@ -1691,7 +1691,7 @@ void databasesCron(void) {
/* Expire keys by random sampling. Not required for slaves
* as master will synthesize DELs for us. */
if
(
server
.
active_expire_enabled
)
{
if
(
server
.
masterhost
==
NULL
)
{
if
(
iAmMaster
()
)
{
activeExpireCycle
(
ACTIVE_EXPIRE_CYCLE_SLOW
);
}
else
{
expireSlaveKeys
();
...
...
@@ -4863,6 +4863,11 @@ int redisIsSupervised(int mode) {
return
0
;
}
int
iAmMaster
(
void
)
{
return
((
!
server
.
cluster_enabled
&&
server
.
masterhost
==
NULL
)
||
(
server
.
cluster_enabled
&&
nodeIsMaster
(
server
.
cluster
->
myself
)));
}
int
main
(
int
argc
,
char
**
argv
)
{
struct
timeval
tv
;
...
...
src/server.h
浏览文件 @
82e18077
...
...
@@ -2393,4 +2393,6 @@ int tlsConfigure(redisTLSContextConfig *ctx_config);
#define redisDebugMark() \
printf("-- MARK %s:%d --\n", __FILE__, __LINE__)
int
iAmMaster
(
void
);
#endif
tests/cluster/tests/14-consistency-check.tcl
0 → 100644
浏览文件 @
82e18077
source
"../tests/includes/init-tests.tcl"
test
"Create a 5 nodes cluster"
{
create_cluster 5 5
}
test
"Cluster should start ok"
{
assert_cluster_state ok
}
test
"Cluster is writable"
{
cluster_write_test 0
}
proc find_non_empty_master
{}
{
set master_id_no
{}
foreach_redis_id id
{
if
{[
RI $id role
]
eq
{
master
}
&&
[
R $id dbsize
]
> 0
}
{
set master_id_no $id
}
}
return $master_id_no
}
proc get_one_of_my_replica
{
id
}
{
set replica_port
[
lindex
[
lindex
[
lindex
[
R $id role
]
2
]
0
]
1
]
set replica_id_num
[
get_instance_id_by_port redis $replica_port
]
return $replica_id_num
}
proc cluster_write_keys_with_expire
{
id ttl
}
{
set prefix
[
randstring 20 20 alpha
]
set port
[
get_instance_attrib redis $id port
]
set cluster
[
redis_cluster 127.0.0.1:$port
]
for
{
set j 100
}
{
$j
< 200
}
{
incr j
}
{
$cluster setex key_expire.$j $ttl $prefix.$j
}
$cluster close
}
proc test_slave_load_expired_keys
{
aof
}
{
test
"Slave expired keys is loaded when restarted: appendonly=
$aof
"
{
set master_id
[
find_non_empty_master
]
set replica_id
[
get_one_of_my_replica $master_id
]
set master_dbsize
[
R $master_id dbsize
]
set slave_dbsize
[
R $replica_id dbsize
]
assert_equal $master_dbsize $slave_dbsize
set data_ttl 5
cluster_write_keys_with_expire $master_id $data_ttl
after 100
set replica_dbsize_1
[
R $replica_id dbsize
]
assert
{
$replica
_dbsize_1 > $slave_dbsize
}
R $replica_id config set appendonly $aof
R $replica_id config rewrite
set start_time
[
clock seconds
]
set end_time
[
expr $start_time+$data_ttl+2
]
R $replica_id save
set replica_dbsize_2
[
R $replica_id dbsize
]
assert
{
$replica
_dbsize_2 > $slave_dbsize
}
kill_instance redis $replica_id
set master_port
[
get_instance_attrib redis $master_id port
]
exec ../../../src/redis-cli -h 127.0.0.1 -p $master_port debug sleep
[
expr $data_ttl+3
]
> /dev/null &
while
{[
clock seconds
]
<= $end_time
}
{
#wait for $data_ttl seconds
}
restart_instance redis $replica_id
wait_for_condition 200 50
{
[
R $replica_id ping
]
eq
{
PONG
}
}
else
{
fail
"replica #
$replica
_id not started"
}
set replica_dbsize_3
[
R $replica_id dbsize
]
assert
{
$replica
_dbsize_3 > $slave_dbsize
}
}
}
test_slave_load_expired_keys no
after 5000
test_slave_load_expired_keys yes
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录