2020-09-16 04:26:10 +00:00
|
|
|
import random
|
2018-07-30 18:32:21 +00:00
|
|
|
import time
|
2020-09-16 04:26:10 +00:00
|
|
|
from multiprocessing.dummy import Pool
|
2018-07-30 18:32:21 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
import pytest
|
2018-07-30 18:32:21 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2019-11-07 15:17:10 +00:00
|
|
|
from helpers.network import PartitionManager
|
2020-09-16 04:26:10 +00:00
|
|
|
from helpers.test_tools import assert_eq_with_retry
|
2018-09-03 14:06:00 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
"""
|
|
|
|
Both ssl_conf.xml and no_ssl_conf.xml have the same port
|
|
|
|
"""
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
def _fill_nodes(nodes, shard):
|
|
|
|
for node in nodes:
|
|
|
|
node.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2020-09-16 04:26:10 +00:00
|
|
|
CREATE DATABASE test;
|
|
|
|
|
|
|
|
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
|
2022-06-23 08:37:52 +00:00
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test{shard}/replicated', '{replica}') PARTITION BY toYYYYMM(date) ORDER BY id;
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
shard=shard, replica=node.name
|
|
|
|
)
|
|
|
|
)
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1",
|
|
|
|
main_configs=[
|
|
|
|
"configs/remote_servers.xml",
|
|
|
|
"configs/ssl_conf.xml",
|
|
|
|
"configs/server.crt",
|
|
|
|
"configs/server.key",
|
|
|
|
"configs/dhparam.pem",
|
|
|
|
],
|
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
|
|
|
node2 = cluster.add_instance(
|
|
|
|
"node2",
|
|
|
|
main_configs=[
|
|
|
|
"configs/remote_servers.xml",
|
|
|
|
"configs/ssl_conf.xml",
|
|
|
|
"configs/server.crt",
|
|
|
|
"configs/server.key",
|
|
|
|
"configs/dhparam.pem",
|
|
|
|
],
|
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def both_https_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
_fill_nodes([node1, node2], 1)
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
def test_both_https(both_https_cluster):
|
|
|
|
node1.query("insert into test_table values ('2017-06-16', 111, 0)")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node1, "SELECT id FROM test_table order by id", "111")
|
|
|
|
assert_eq_with_retry(node2, "SELECT id FROM test_table order by id", "111")
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
node2.query("insert into test_table values ('2017-06-17', 222, 1)")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node1, "SELECT id FROM test_table order by id", "111\n222")
|
|
|
|
assert_eq_with_retry(node2, "SELECT id FROM test_table order by id", "111\n222")
|
2018-07-30 18:32:21 +00:00
|
|
|
|
2019-11-07 15:17:10 +00:00
|
|
|
|
|
|
|
def test_replication_after_partition(both_https_cluster):
|
|
|
|
node1.query("truncate table test_table")
|
|
|
|
node2.query("truncate table test_table")
|
|
|
|
|
|
|
|
manager = PartitionManager()
|
|
|
|
|
|
|
|
def close(num):
|
|
|
|
manager.partition_instances(node1, node2, port=9010)
|
|
|
|
time.sleep(1)
|
|
|
|
manager.heal_all()
|
|
|
|
|
|
|
|
def insert_data_and_check(num):
|
|
|
|
node1.query("insert into test_table values('2019-10-15', {}, 888)".format(num))
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
|
|
closing_pool = Pool(1)
|
|
|
|
inserting_pool = Pool(5)
|
|
|
|
cres = closing_pool.map_async(close, [random.randint(1, 3) for _ in range(10)])
|
2020-10-02 16:54:07 +00:00
|
|
|
ires = inserting_pool.map_async(insert_data_and_check, list(range(100)))
|
2019-11-07 15:17:10 +00:00
|
|
|
|
|
|
|
cres.wait()
|
|
|
|
ires.wait()
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node1, "SELECT count() FROM test_table", "100")
|
|
|
|
assert_eq_with_retry(node2, "SELECT count() FROM test_table", "100")
|
2019-11-07 15:17:10 +00:00
|
|
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
node3 = cluster.add_instance(
|
|
|
|
"node3",
|
|
|
|
main_configs=["configs/remote_servers.xml", "configs/no_ssl_conf.xml"],
|
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
|
|
|
node4 = cluster.add_instance(
|
|
|
|
"node4",
|
|
|
|
main_configs=["configs/remote_servers.xml", "configs/no_ssl_conf.xml"],
|
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
2019-11-07 15:17:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def both_http_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
_fill_nodes([node3, node4], 2)
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
def test_both_http(both_http_cluster):
|
|
|
|
node3.query("insert into test_table values ('2017-06-16', 111, 0)")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node3, "SELECT id FROM test_table order by id", "111")
|
|
|
|
assert_eq_with_retry(node4, "SELECT id FROM test_table order by id", "111")
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
node4.query("insert into test_table values ('2017-06-17', 222, 1)")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node3, "SELECT id FROM test_table order by id", "111\n222")
|
|
|
|
assert_eq_with_retry(node4, "SELECT id FROM test_table order by id", "111\n222")
|
2018-07-30 18:32:21 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
node5 = cluster.add_instance(
|
|
|
|
"node5",
|
|
|
|
main_configs=[
|
|
|
|
"configs/remote_servers.xml",
|
|
|
|
"configs/ssl_conf.xml",
|
|
|
|
"configs/server.crt",
|
|
|
|
"configs/server.key",
|
|
|
|
"configs/dhparam.pem",
|
|
|
|
],
|
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
|
|
|
node6 = cluster.add_instance(
|
|
|
|
"node6",
|
|
|
|
main_configs=["configs/remote_servers.xml", "configs/no_ssl_conf.xml"],
|
|
|
|
with_zookeeper=True,
|
|
|
|
)
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def mixed_protocol_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
_fill_nodes([node5, node6], 3)
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
def test_mixed_protocol(mixed_protocol_cluster):
|
|
|
|
node5.query("insert into test_table values ('2017-06-16', 111, 0)")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node5, "SELECT id FROM test_table order by id", "111")
|
|
|
|
assert_eq_with_retry(node6, "SELECT id FROM test_table order by id", "")
|
2018-07-30 18:32:21 +00:00
|
|
|
|
|
|
|
node6.query("insert into test_table values ('2017-06-17', 222, 1)")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert_eq_with_retry(node5, "SELECT id FROM test_table order by id", "111")
|
|
|
|
assert_eq_with_retry(node6, "SELECT id FROM test_table order by id", "222")
|