Skip to content

Commit

Permalink
Move test to another file
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgarbar committed May 13, 2024
1 parent 5f2228c commit 7543cd3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
</cluster>
</remote_servers>

<default_replica_path>/clickhouse/tables/{database}/{table}/{uuid}</default_replica_path>

<macros>
<shard>01</shard>
</macros>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<shard>01</shard>
</macros>

<default_replica_path>/lol/kek/'/{uuid}</default_replica_path>
<default_replica_path>/clickhouse/'/{database}/{table}/{uuid}</default_replica_path>

</clickhouse>
53 changes: 5 additions & 48 deletions tests/integration/test_modify_engine_on_restart/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import pytest
from test_modify_engine_on_restart.common import (
check_flags_deleted,
set_convert_flags,
get_table_path,
)
from test_modify_engine_on_restart.common import check_flags_deleted, set_convert_flags
from helpers.cluster import ClickHouseCluster

cluster = ClickHouseCluster(__file__)
Expand Down Expand Up @@ -40,8 +36,8 @@ def started_cluster():
cluster.shutdown()


def q(node, query, database=database_name):
return node.query(database=database, sql=query)
def q(node, query):
return node.query(database=database_name, sql=query)


def create_tables():
Expand Down Expand Up @@ -124,7 +120,7 @@ def check_replica_added():

q(
ch2,
f"CREATE TABLE rmt ( A Int64, D Date, S String ) ENGINE ReplicatedMergeTree('/clickhouse/tables/{database_name}/rmt/{uuid}', '{{replica}}') PARTITION BY toYYYYMM(D) ORDER BY A",
f"CREATE TABLE rmt ( A Int64, D Date, S String ) ENGINE ReplicatedMergeTree('/clickhouse/tables/{uuid}/{{shard}}', '{{replica}}') PARTITION BY toYYYYMM(D) ORDER BY A",
)

ch2.query(database=database_name, sql="SYSTEM SYNC REPLICA rmt", timeout=20)
Expand All @@ -140,7 +136,7 @@ def check_replica_added():


def test_modify_engine_on_restart(started_cluster):
ch1.query("CREATE DATABASE IF NOT EXISTS " + database_name + " ON CLUSTER cluster")
ch1.query("CREATE DATABASE " + database_name + " ON CLUSTER cluster")

create_tables()

Expand All @@ -163,42 +159,3 @@ def test_modify_engine_on_restart(started_cluster):
ch1.restart_clickhouse()

check_tables(True)


def test_modify_engine_fails_if_zk_path_exists(started_cluster):
database_name = "zk_path"
ch1.query("CREATE DATABASE " + database_name + " ON CLUSTER cluster")

q(
ch1,
"CREATE TABLE already_exists_1 ( A Int64, D Date, S String ) ENGINE MergeTree() PARTITION BY toYYYYMM(D) ORDER BY A;",
database_name,
)
uuid = q(
ch1,
f"SELECT uuid FROM system.tables WHERE table = 'already_exists_1' and database = '{database_name}'",
database_name,
).strip("'[]\n")

q(
ch1,
f"CREATE TABLE already_exists_2 ( A Int64, D Date, S String ) ENGINE ReplicatedMergeTree('/clickhouse/tables/{database_name}/already_exists_1/{uuid}', 'r2') PARTITION BY toYYYYMM(D) ORDER BY A;",
database_name,
)

set_convert_flags(ch1, database_name, ["already_exists_1"])

table_data_path = get_table_path(ch1, "already_exists_1", database_name)

ch1.stop_clickhouse()
ch1.start_clickhouse(retry_start=False, expected_to_fail=True)

# Check if we can cancel convertation
ch1.exec_in_container(
[
"bash",
"-c",
f"rm {table_data_path}convert_to_replicated",
]
)
ch1.start_clickhouse()
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import pytest
from test_modify_engine_on_restart.common import check_flags_deleted, set_convert_flags
from test_modify_engine_on_restart.common import (
check_flags_deleted,
get_table_path,
set_convert_flags,
)
from helpers.cluster import ClickHouseCluster

cluster = ClickHouseCluster(__file__)
ch1 = cluster.add_instance(
"ch1",
main_configs=[
"configs/config.d/clusters_unusual.xml",
"configs/config.d/clusters_zk_path.xml",
"configs/config.d/distributed_ddl.xml",
],
with_zookeeper=True,
Expand All @@ -27,8 +31,8 @@ def started_cluster():
cluster.shutdown()


def q(node, query):
return node.query(database=database_name, sql=query)
def q(node, query, database=database_name):
return node.query(database=database, sql=query)


def create_tables():
Expand Down Expand Up @@ -63,7 +67,7 @@ def check_tables():
)
.strip()
.startswith(
"ReplicatedReplacingMergeTree(\\'/lol/kek/\\\\\\'/{uuid}\\', \\'{replica}\\', D)"
"ReplicatedReplacingMergeTree(\\'/clickhouse/\\\\\\'/{database}/{table}/{uuid}\\', \\'{replica}\\', D)"
)
)
assert (
Expand All @@ -73,7 +77,7 @@ def check_tables():
)
.strip()
.startswith(
"ReplicatedVersionedCollapsingMergeTree(\\'/lol/kek/\\\\\\'/{uuid}\\', \\'{replica}\\', Sign, Version)"
"ReplicatedVersionedCollapsingMergeTree(\\'/clickhouse/\\\\\\'/{database}/{table}/{uuid}\\', \\'{replica}\\', Sign, Version)"
)
)

Expand All @@ -90,3 +94,42 @@ def test_modify_engine_on_restart_with_unusual_path(started_cluster):
check_flags_deleted(ch1, database_name, ["replacing_ver", "collapsing_ver"])

check_tables()


def test_modify_engine_fails_if_zk_path_exists(started_cluster):
database_name = "zk_path"
ch1.query("CREATE DATABASE " + database_name + " ON CLUSTER cluster")

q(
ch1,
"CREATE TABLE already_exists_1 ( A Int64, D Date, S String ) ENGINE MergeTree() PARTITION BY toYYYYMM(D) ORDER BY A;",
database_name,
)
uuid = q(
ch1,
f"SELECT uuid FROM system.tables WHERE table = 'already_exists_1' and database = '{database_name}'",
database_name,
).strip("'[]\n")

q(
ch1,
f"CREATE TABLE already_exists_2 ( A Int64, D Date, S String ) ENGINE ReplicatedMergeTree('/clickhouse/\\'/{database_name}/already_exists_1/{uuid}', 'r2') PARTITION BY toYYYYMM(D) ORDER BY A;",
database_name,
)

set_convert_flags(ch1, database_name, ["already_exists_1"])

table_data_path = get_table_path(ch1, "already_exists_1", database_name)

ch1.stop_clickhouse()
ch1.start_clickhouse(retry_start=False, expected_to_fail=True)

# Check if we can cancel convertation
ch1.exec_in_container(
[
"bash",
"-c",
f"rm {table_data_path}convert_to_replicated",
]
)
ch1.start_clickhouse()

0 comments on commit 7543cd3

Please sign in to comment.