2019-11-16 23:13:29 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-02-26 12:45:20 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster, CLICKHOUSE_CI_MIN_TESTED_VERSION
|
2019-11-16 23:13:29 +00:00
|
|
|
from helpers.test_tools import assert_eq_with_retry
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2024-02-26 12:45:20 +00:00
|
|
|
node_oldest = cluster.add_instance(
|
|
|
|
"node_oldest",
|
|
|
|
image="clickhouse/clickhouse-server",
|
|
|
|
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
|
2020-09-16 04:26:10 +00:00
|
|
|
with_installed_binary=True,
|
|
|
|
main_configs=["configs/config.d/test_cluster.xml"],
|
|
|
|
)
|
2024-02-26 12:45:20 +00:00
|
|
|
old_nodes = [node_oldest]
|
2019-11-16 23:13:29 +00:00
|
|
|
new_node = cluster.add_instance("node_new")
|
|
|
|
|
|
|
|
|
|
|
|
def query_from_one_node_to_another(client_node, server_node, query):
|
2020-09-16 04:26:10 +00:00
|
|
|
client_node.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
|
|
|
"/usr/bin/clickhouse client --host {} --query {!r}".format(
|
|
|
|
server_node.name, query
|
2022-03-22 16:39:58 +00:00
|
|
|
),
|
|
|
|
]
|
2020-09-16 04:26:10 +00:00
|
|
|
)
|
2019-11-16 23:13:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def setup_nodes():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
for n in old_nodes + [new_node]:
|
|
|
|
n.query(
|
|
|
|
"""CREATE TABLE test_table (id UInt32, value UInt64) ENGINE = MergeTree() ORDER BY tuple()"""
|
|
|
|
)
|
|
|
|
|
|
|
|
for n in old_nodes:
|
2020-09-16 04:26:10 +00:00
|
|
|
n.query(
|
|
|
|
"""CREATE TABLE dist_table AS test_table ENGINE = Distributed('test_cluster', 'default', 'test_table')"""
|
|
|
|
)
|
2019-11-16 23:13:29 +00:00
|
|
|
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_client_is_older_than_server(setup_nodes):
|
|
|
|
server = new_node
|
|
|
|
for i, client in enumerate(old_nodes):
|
|
|
|
query_from_one_node_to_another(
|
|
|
|
client, server, "INSERT INTO test_table VALUES (1, {})".format(i)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2019-11-16 23:13:29 +00:00
|
|
|
|
|
|
|
for client in old_nodes:
|
|
|
|
query_from_one_node_to_another(client, server, "SELECT COUNT() FROM test_table")
|
|
|
|
|
|
|
|
assert (
|
|
|
|
server.query("SELECT COUNT() FROM test_table WHERE id=1")
|
|
|
|
== str(len(old_nodes)) + "\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2019-11-16 23:13:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_server_is_older_than_client(setup_nodes):
|
|
|
|
client = new_node
|
|
|
|
for i, server in enumerate(old_nodes):
|
|
|
|
query_from_one_node_to_another(
|
|
|
|
client, server, "INSERT INTO test_table VALUES (2, {})".format(i)
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2019-11-16 23:13:29 +00:00
|
|
|
|
|
|
|
for server in old_nodes:
|
|
|
|
query_from_one_node_to_another(client, server, "SELECT COUNT() FROM test_table")
|
|
|
|
|
|
|
|
for server in old_nodes:
|
|
|
|
assert server.query("SELECT COUNT() FROM test_table WHERE id=2") == "1\n"
|
|
|
|
|
|
|
|
|
|
|
|
def test_distributed_query_initiator_is_older_than_shard(setup_nodes):
|
|
|
|
shard = new_node
|
2024-02-26 12:45:20 +00:00
|
|
|
for i, initiator in enumerate(old_nodes):
|
2019-11-16 23:13:29 +00:00
|
|
|
initiator.query("INSERT INTO dist_table VALUES (3, {})".format(i))
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
assert_eq_with_retry(
|
|
|
|
shard,
|
|
|
|
"SELECT COUNT() FROM test_table WHERE id=3",
|
2024-02-26 12:45:20 +00:00
|
|
|
str(len(old_nodes)),
|
2020-09-16 04:26:10 +00:00
|
|
|
)
|
|
|
|
assert_eq_with_retry(
|
|
|
|
initiator,
|
|
|
|
"SELECT COUNT() FROM dist_table WHERE id=3",
|
2024-02-26 12:45:20 +00:00
|
|
|
str(len(old_nodes)),
|
2020-09-16 04:26:10 +00:00
|
|
|
)
|