2018-01-17 19:22:09 +00:00
|
|
|
import time
|
2020-09-16 04:26:10 +00:00
|
|
|
import pytest
|
2021-05-21 13:29:43 +00:00
|
|
|
import logging
|
2020-09-16 04:26:10 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2023-08-04 14:18:50 +00:00
|
|
|
from helpers.test_tools import assert_eq_with_retry
|
2017-08-30 16:25:34 +00:00
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
cluster = ClickHouseCluster(
|
|
|
|
__file__, zookeeper_config_path="configs/zookeeper_config_root_a.xml"
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
node1 = cluster.add_instance(
|
2022-03-22 16:39:58 +00:00
|
|
|
"node1",
|
2021-05-21 13:29:43 +00:00
|
|
|
with_zookeeper=True,
|
|
|
|
main_configs=["configs/remote_servers.xml", "configs/zookeeper_config_root_a.xml"],
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-05-21 13:29:43 +00:00
|
|
|
node2 = cluster.add_instance(
|
2022-03-22 16:39:58 +00:00
|
|
|
"node2",
|
2021-05-21 13:29:43 +00:00
|
|
|
with_zookeeper=True,
|
|
|
|
main_configs=["configs/remote_servers.xml", "configs/zookeeper_config_root_a.xml"],
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-05-21 13:29:43 +00:00
|
|
|
node3 = cluster.add_instance(
|
2022-03-22 16:39:58 +00:00
|
|
|
"node3",
|
2021-05-21 13:29:43 +00:00
|
|
|
with_zookeeper=True,
|
|
|
|
main_configs=["configs/remote_servers.xml", "configs/zookeeper_config_root_b.xml"],
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2017-08-30 16:25:34 +00:00
|
|
|
|
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
def create_zk_roots(zk):
|
|
|
|
zk.ensure_path("/root_a")
|
|
|
|
zk.ensure_path("/root_b")
|
|
|
|
logging.debug(f"Create ZK roots:{zk.get_children('/')}")
|
2017-08-30 16:25:34 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def started_cluster():
|
2017-08-30 16:25:34 +00:00
|
|
|
try:
|
2021-05-21 13:29:43 +00:00
|
|
|
cluster.add_zookeeper_startup_command(create_zk_roots)
|
|
|
|
cluster.start()
|
2017-08-30 16:25:34 +00:00
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
yield cluster
|
2017-08-30 16:25:34 +00:00
|
|
|
|
|
|
|
finally:
|
2021-05-21 13:29:43 +00:00
|
|
|
cluster.shutdown()
|
2017-08-30 16:25:34 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
def test_chroot_with_same_root(started_cluster):
|
|
|
|
for i, node in enumerate([node1, node2]):
|
2021-06-16 12:31:19 +00:00
|
|
|
node.query("DROP TABLE IF EXISTS simple SYNC")
|
2021-05-21 13:29:43 +00:00
|
|
|
node.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2018-01-17 19:22:09 +00:00
|
|
|
CREATE TABLE simple (date Date, id UInt32)
|
2022-06-23 08:37:52 +00:00
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/0/simple', '{replica}') PARTITION BY toYYYYMM(date) ORDER BY id;
|
2021-05-21 13:29:43 +00:00
|
|
|
""".format(
|
|
|
|
replica=node.name
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-05-21 13:29:43 +00:00
|
|
|
for j in range(2): # Second insert to test deduplication
|
|
|
|
node.query("INSERT INTO simple VALUES ({0}, {0})".format(i))
|
|
|
|
|
2023-08-05 12:07:55 +00:00
|
|
|
node1.query("SYSTEM SYNC REPLICA simple")
|
2023-08-05 12:05:06 +00:00
|
|
|
assert_eq_with_retry(node1, "select count() from simple", "2")
|
2023-08-05 12:07:55 +00:00
|
|
|
node2.query("SYSTEM SYNC REPLICA simple")
|
2023-08-05 12:05:06 +00:00
|
|
|
assert_eq_with_retry(node2, "select count() from simple", "2")
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-05-21 13:29:43 +00:00
|
|
|
|
|
|
|
def test_chroot_with_different_root(started_cluster):
|
|
|
|
for i, node in [(1, node1), (3, node3)]:
|
2021-06-16 12:31:19 +00:00
|
|
|
node.query("DROP TABLE IF EXISTS simple_different SYNC")
|
2021-05-21 13:29:43 +00:00
|
|
|
node.query(
|
2022-03-22 16:39:58 +00:00
|
|
|
"""
|
2021-05-21 13:29:43 +00:00
|
|
|
CREATE TABLE simple_different (date Date, id UInt32)
|
2022-06-23 08:37:52 +00:00
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/0/simple_different', '{replica}') PARTITION BY toYYYYMM(date) ORDER BY id;
|
2021-05-21 13:29:43 +00:00
|
|
|
""".format(
|
|
|
|
replica=node.name
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-05-21 13:29:43 +00:00
|
|
|
for j in range(2): # Second insert to test deduplication
|
|
|
|
node.query("INSERT INTO simple_different VALUES ({0}, {0})".format(i))
|
|
|
|
|
2023-08-05 12:07:55 +00:00
|
|
|
node1.query("SYSTEM SYNC REPLICA simple_different")
|
2023-08-05 12:05:06 +00:00
|
|
|
assert_eq_with_retry(node1, "select count() from simple_different", "1")
|
2023-08-05 14:52:44 +00:00
|
|
|
node3.query("SYSTEM SYNC REPLICA simple_different")
|
2023-08-05 12:05:06 +00:00
|
|
|
assert_eq_with_retry(node3, "select count() from simple_different", "1")
|