Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
c99f3d7e
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c99f3d7e
编写于
8月 01, 2017
作者:
A
Alexey Zatelepin
提交者:
alexey-milovidov
8月 13, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test [#CLICKHOUSE-3151]
上级
b469ef17
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
25 deletion
+55
-25
dbms/tests/integration/helpers/network.py
dbms/tests/integration/helpers/network.py
+9
-3
dbms/tests/integration/test_delayed_replica_failover/configs/remote_servers.xml
.../test_delayed_replica_failover/configs/remote_servers.xml
+13
-2
dbms/tests/integration/test_delayed_replica_failover/test.py
dbms/tests/integration/test_delayed_replica_failover/test.py
+33
-20
未找到文件。
dbms/tests/integration/helpers/network.py
浏览文件 @
c99f3d7e
...
...
@@ -36,12 +36,18 @@ class PartitionManager:
self
.
_delete_rule
({
'destination'
:
instance
.
ip_address
,
'source_port'
:
2181
,
'action'
:
action
})
def
partition_instances
(
self
,
left
,
right
,
action
=
'DROP'
):
def
partition_instances
(
self
,
left
,
right
,
port
=
None
,
action
=
'DROP'
):
self
.
_check_instance
(
left
)
self
.
_check_instance
(
right
)
self
.
_add_rule
({
'source'
:
left
.
ip_address
,
'destination'
:
right
.
ip_address
,
'action'
:
action
})
self
.
_add_rule
({
'source'
:
right
.
ip_address
,
'destination'
:
left
.
ip_address
,
'action'
:
action
})
def
create_rule
(
src
,
dst
):
rule
=
{
'source'
:
src
.
ip_address
,
'destination'
:
dst
.
ip_address
,
'action'
:
action
}
if
port
is
not
None
:
rule
[
'destination_port'
]
=
port
return
rule
self
.
_add_rule
(
create_rule
(
left
,
right
))
self
.
_add_rule
(
create_rule
(
right
,
left
))
def
heal_all
(
self
):
...
...
dbms/tests/integration/test_delayed_replica_failover/configs/remote_servers.xml
浏览文件 @
c99f3d7e
...
...
@@ -4,11 +4,22 @@
<shard>
<internal_replication>
true
</internal_replication>
<replica>
<host>
replica
1
</host>
<host>
node_1_
1
</host>
<port>
9000
</port>
</replica>
<replica>
<host>
replica2
</host>
<host>
node_1_2
</host>
<port>
9000
</port>
</replica>
</shard>
<shard>
<internal_replication>
true
</internal_replication>
<replica>
<host>
node_2_1
</host>
<port>
9000
</port>
</replica>
<replica>
<host>
node_2_2
</host>
<port>
9000
</port>
</replica>
</shard>
...
...
dbms/tests/integration/test_delayed_replica_failover/test.py
浏览文件 @
c99f3d7e
...
...
@@ -7,21 +7,28 @@ from helpers.network import PartitionManager
cluster
=
ClickHouseCluster
(
__file__
)
instance_with_dist_table
=
cluster
.
add_instance
(
'instance_with_dist_table'
,
main_configs
=
[
'configs/remote_servers.xml'
])
replica1
=
cluster
.
add_instance
(
'replica1'
,
with_zookeeper
=
True
)
replica2
=
cluster
.
add_instance
(
'replica2'
,
with_zookeeper
=
True
)
# Cluster with 2 shards of 2 replicas each. node_1_1 is the instance with Distributed table.
# Thus we have a shard with a local replica and a shard with remote replicas.
node_1_1
=
instance_with_dist_table
=
cluster
.
add_instance
(
'node_1_1'
,
with_zookeeper
=
True
,
main_configs
=
[
'configs/remote_servers.xml'
])
node_1_2
=
cluster
.
add_instance
(
'node_1_2'
,
with_zookeeper
=
True
)
node_2_1
=
cluster
.
add_instance
(
'node_2_1'
,
with_zookeeper
=
True
)
node_2_2
=
cluster
.
add_instance
(
'node_2_2'
,
with_zookeeper
=
True
)
@
pytest
.
fixture
(
scope
=
"module"
)
def
started_cluster
():
try
:
cluster
.
start
()
for
replica
in
(
replica1
,
replica2
):
replica
.
query
(
"CREATE TABLE replicated (d Date, x UInt32) ENGINE = "
"ReplicatedMergeTree('/clickhouse/tables/replicated', '{instance}', d, d, 8192)"
)
for
shard
in
(
1
,
2
):
for
replica
in
(
1
,
2
):
node
=
cluster
.
instances
[
'node_{}_{}'
.
format
(
shard
,
replica
)]
node
.
query
(
'''
CREATE TABLE replicated (d Date, x UInt32) ENGINE =
ReplicatedMergeTree('/clickhouse/tables/{shard}/replicated', '{instance}', d, d, 8192)'''
.
format
(
shard
=
shard
,
instance
=
node
.
name
))
instance_with_dist_table
.
query
(
node_1_1
.
query
(
"CREATE TABLE distributed (d Date, x UInt32) ENGINE = "
"Distributed('test_cluster', 'default', 'replicated')"
)
...
...
@@ -33,36 +40,42 @@ def started_cluster():
def
test
(
started_cluster
):
with
PartitionManager
()
as
pm
:
pm
.
partition_instances
(
replica1
,
replica2
)
# Hinder replication between replicas of the same shard, but leave the possibility of distributed connection.
pm
.
partition_instances
(
node_1_1
,
node_1_2
,
port
=
9009
)
pm
.
partition_instances
(
node_2_1
,
node_2_2
,
port
=
9009
)
replica2
.
query
(
"INSERT INTO replicated VALUES ('2017-05-08', 1)"
)
node_1_2
.
query
(
"INSERT INTO replicated VALUES ('2017-05-08', 1)"
)
node_2_2
.
query
(
"INSERT INTO replicated VALUES ('2017-05-08', 2)"
)
time
.
sleep
(
1
)
# accrue replica delay
assert
replica1
.
query
(
"SELECT count() FROM replicated"
).
strip
()
==
''
assert
replica2
.
query
(
"SELECT count() FROM replicated"
).
strip
()
==
'1'
assert
node_1_1
.
query
(
"SELECT sum(x) FROM replicated"
).
strip
()
==
''
assert
node_1_2
.
query
(
"SELECT sum(x) FROM replicated"
).
strip
()
==
'1'
assert
node_2_1
.
query
(
"SELECT sum(x) FROM replicated"
).
strip
()
==
''
assert
node_2_2
.
query
(
"SELECT sum(x) FROM replicated"
).
strip
()
==
'2'
# With in_order balancing
replica1 i
s chosen.
# With in_order balancing
first replica
s chosen.
assert
instance_with_dist_table
.
query
(
"SELECT count() FROM distributed SETTINGS load_balancing='in_order'"
).
strip
()
==
''
# When we set max_replica_delay,
replica1
must be excluded.
# When we set max_replica_delay,
first replicas
must be excluded.
assert
instance_with_dist_table
.
query
(
'''
SELECT
count(
) FROM distributed SETTINGS
SELECT
sum(x
) FROM distributed SETTINGS
load_balancing='in_order',
max_replica_delay_for_distributed_queries=1
'''
).
strip
()
==
'
1
'
'''
).
strip
()
==
'
3
'
pm
.
drop_instance_zk_connections
(
replica2
)
pm
.
drop_instance_zk_connections
(
node_1_2
)
pm
.
drop_instance_zk_connections
(
node_2_2
)
time
.
sleep
(
4
)
# allow pings to zookeeper to timeout (must be greater than ZK session timeout).
# At this point all replicas are stale, but the query must still go to
replica2 which is the least stale one
.
# At this point all replicas are stale, but the query must still go to
second replicas which are the least stale ones
.
assert
instance_with_dist_table
.
query
(
'''
SELECT
count(
) FROM distributed SETTINGS
SELECT
sum(x
) FROM distributed SETTINGS
load_balancing='in_order',
max_replica_delay_for_distributed_queries=1
'''
).
strip
()
==
'
1
'
'''
).
strip
()
==
'
3
'
# If we forbid stale replicas, the query must fail.
with
pytest
.
raises
(
Exception
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录