ClickHouse/tests/integration/test_replicated_merge_tree_compatibility/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.4 KiB
Python
Raw Normal View History

2021-09-22 15:44:01 +00:00
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
"node1",
with_zookeeper=True,
image="yandex/clickhouse-server",
tag="20.12.4.5",
stay_alive=True,
with_installed_binary=True,
allow_analyzer=False,
)
node2 = cluster.add_instance(
"node2",
with_zookeeper=True,
image="yandex/clickhouse-server",
tag="20.12.4.5",
stay_alive=True,
with_installed_binary=True,
allow_analyzer=False,
)
2021-09-22 15:44:01 +00:00
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
except Exception as ex:
print(ex)
finally:
cluster.shutdown()
2021-09-22 15:44:01 +00:00
def test_replicated_merge_tree_defaults_compatibility(started_cluster):
# This test checks, that result of parsing list of columns with defaults
# from 'CREATE/ATTACH' is compatible with parsing from zookeeper metadata on different versions.
# We create table and write 'columns' node in zookeeper with old version, than restart with new version
# drop and try recreate one replica. During startup of table structure is checked between 'CREATE' query and zookeeper.
create_query = """
2021-09-22 15:44:01 +00:00
CREATE TABLE test.table
(
a UInt32,
b String DEFAULT If(a = 0, 'true', 'false'),
c String DEFAULT Cast(a, 'String')
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/table', '{replica}')
ORDER BY a
"""
2021-09-22 15:44:01 +00:00
for node in (node1, node2):
2022-06-23 19:40:05 +00:00
node.query(
"CREATE DATABASE test ENGINE = Ordinary",
settings={"allow_deprecated_database_ordinary": 1},
)
2021-09-22 15:44:01 +00:00
node.query(create_query.format(replica=node.name))
node1.query("DETACH TABLE test.table")
node2.query("SYSTEM DROP REPLICA 'node1' FROM TABLE test.table")
node1.exec_in_container(
["bash", "-c", "rm /var/lib/clickhouse/metadata/test/table.sql"]
)
2021-09-22 15:44:01 +00:00
node1.exec_in_container(["bash", "-c", "rm -r /var/lib/clickhouse/data/test/table"])
zk = cluster.get_kazoo_client("zoo1")
2021-09-22 15:44:01 +00:00
exists_replica_1 = zk.exists("/clickhouse/tables/test/table/replicas/node1")
assert exists_replica_1 == None
node1.restart_with_latest_version()
node2.restart_with_latest_version()
node1.query(create_query.format(replica=1))
assert node1.query("EXISTS TABLE test.table") == "1\n"