2024-09-27 10:19:39 +00:00
|
|
|
import os
|
2020-11-03 07:52:31 +00:00
|
|
|
import time
|
2024-09-27 10:19:39 +00:00
|
|
|
|
2020-11-03 07:52:31 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.client import QueryRuntimeException
|
2024-09-27 10:19:39 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2020-11-03 07:52:31 +00:00
|
|
|
from helpers.test_tools import assert_eq_with_retry
|
|
|
|
|
2021-05-21 09:09:10 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2020-11-03 07:52:31 +00:00
|
|
|
node = cluster.add_instance("node", with_zookeeper=True)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_reload_auxiliary_zookeepers(start_cluster):
|
|
|
|
node.query(
|
|
|
|
"CREATE TABLE simple (date Date, id UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/0/simple', 'node') ORDER BY tuple() PARTITION BY date;"
|
|
|
|
)
|
|
|
|
node.query("INSERT INTO simple VALUES ('2020-08-27', 1)")
|
|
|
|
|
|
|
|
node.query(
|
|
|
|
"CREATE TABLE simple2 (date Date, id UInt32) ENGINE = ReplicatedMergeTree('/clickhouse/tables/1/simple', 'node') ORDER BY tuple() PARTITION BY date;"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Add an auxiliary zookeeper
|
2021-09-25 04:08:34 +00:00
|
|
|
new_config = """<clickhouse>
|
2020-11-03 07:52:31 +00:00
|
|
|
<zookeeper>
|
|
|
|
<node index="1">
|
|
|
|
<host>zoo1</host>
|
|
|
|
<port>2181</port>
|
|
|
|
</node>
|
|
|
|
<node index="2">
|
|
|
|
<host>zoo2</host>
|
|
|
|
<port>2181</port>
|
|
|
|
</node>
|
|
|
|
<node index="3">
|
|
|
|
<host>zoo3</host>
|
|
|
|
<port>2181</port>
|
|
|
|
</node>
|
|
|
|
<session_timeout_ms>2000</session_timeout_ms>
|
|
|
|
</zookeeper>
|
|
|
|
<auxiliary_zookeepers>
|
|
|
|
<zookeeper2>
|
|
|
|
<node index="1">
|
|
|
|
<host>zoo1</host>
|
|
|
|
<port>2181</port>
|
|
|
|
</node>
|
|
|
|
<node index="2">
|
|
|
|
<host>zoo2</host>
|
|
|
|
<port>2181</port>
|
|
|
|
</node>
|
|
|
|
</zookeeper2>
|
|
|
|
</auxiliary_zookeepers>
|
2021-09-25 04:08:34 +00:00
|
|
|
</clickhouse>"""
|
2022-03-22 16:39:58 +00:00
|
|
|
node.replace_config(
|
|
|
|
"/etc/clickhouse-server/conf.d/zookeeper_config.xml", new_config
|
|
|
|
)
|
2020-11-03 07:52:31 +00:00
|
|
|
|
2021-02-19 16:22:47 +00:00
|
|
|
node.query("SYSTEM RELOAD CONFIG")
|
2020-11-03 07:52:31 +00:00
|
|
|
|
2021-05-26 12:06:31 +00:00
|
|
|
time.sleep(5)
|
|
|
|
|
2020-11-03 07:52:31 +00:00
|
|
|
node.query(
|
|
|
|
"ALTER TABLE simple2 FETCH PARTITION '2020-08-27' FROM 'zookeeper2:/clickhouse/tables/0/simple';"
|
|
|
|
)
|
|
|
|
node.query("ALTER TABLE simple2 ATTACH PARTITION '2020-08-27';")
|
|
|
|
assert node.query("SELECT id FROM simple2").strip() == "1"
|
|
|
|
|
2021-09-25 04:08:34 +00:00
|
|
|
new_config = """<clickhouse>
|
2020-11-03 07:52:31 +00:00
|
|
|
<zookeeper>
|
|
|
|
<node index="1">
|
|
|
|
<host>zoo2</host>
|
|
|
|
<port>2181</port>
|
|
|
|
</node>
|
|
|
|
<session_timeout_ms>2000</session_timeout_ms>
|
|
|
|
</zookeeper>
|
2021-09-25 04:08:34 +00:00
|
|
|
</clickhouse>"""
|
2022-03-22 16:39:58 +00:00
|
|
|
node.replace_config(
|
|
|
|
"/etc/clickhouse-server/conf.d/zookeeper_config.xml", new_config
|
|
|
|
)
|
2021-02-19 19:32:50 +00:00
|
|
|
node.query("SYSTEM RELOAD CONFIG")
|
2021-05-26 12:06:31 +00:00
|
|
|
time.sleep(5)
|
|
|
|
|
2020-11-03 07:52:31 +00:00
|
|
|
with pytest.raises(QueryRuntimeException):
|
|
|
|
node.query(
|
|
|
|
"ALTER TABLE simple2 FETCH PARTITION '2020-08-27' FROM 'zookeeper2:/clickhouse/tables/0/simple';"
|
|
|
|
)
|
|
|
|
assert node.query("SELECT id FROM simple2").strip() == "1"
|