ClickHouse/tests/integration/test_system_detached_tables/test.py

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

113 lines
3.6 KiB
Python
Raw Normal View History

2024-06-14 12:31:52 +00:00
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
2024-07-03 12:12:09 +00:00
node = cluster.add_instance(
"replica1",
2024-07-03 11:36:04 +00:00
with_zookeeper=True,
main_configs=["configs/remote_servers.xml"],
macros={"replica": "replica1"},
stay_alive=True,
)
2024-06-14 12:31:52 +00:00
2024-07-03 12:22:32 +00:00
2024-06-14 12:31:52 +00:00
@pytest.fixture(scope="module", autouse=True)
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2024-07-03 12:12:09 +00:00
2024-07-03 11:36:04 +00:00
@pytest.mark.parametrize(
"db_name,db_engine,table_engine,table_engine_params",
[
pytest.param(
2024-07-03 12:12:09 +00:00
"test_db_atomic",
"Atomic",
"MergeTree",
"ORDER BY n",
id="Atomic db with MergeTree table",
2024-07-03 11:36:04 +00:00
),
pytest.param(
2024-07-03 12:12:09 +00:00
"test_db_lazy",
"Lazy(60)",
"Log",
"",
id="Lazy db with Log table",
2024-07-03 11:36:04 +00:00
),
pytest.param(
2024-07-03 12:12:09 +00:00
"test_db_repl",
2024-07-03 12:22:32 +00:00
"Replicated('/clickhouse/tables/test_table','shard1', 'replica1')",
"ReplicatedMergeTree",
2024-07-03 12:12:09 +00:00
"ORDER BY n",
id="Replicated db with ReplicatedMergeTree table",
2024-07-03 11:36:04 +00:00
),
],
)
2024-07-03 12:22:32 +00:00
def test_system_detached_tables(
start_cluster, db_name, db_engine, table_engine, table_engine_params
):
2024-07-03 11:36:04 +00:00
node.query(f"CREATE DATABASE IF NOT EXISTS {db_name} ENGINE={db_engine};")
2024-06-14 12:31:52 +00:00
2024-07-03 12:12:09 +00:00
node.query(
f"CREATE TABLE {db_name}.test_table (n Int64) ENGINE={table_engine} {table_engine_params};"
)
node.query(
f"CREATE TABLE {db_name}.test_table_perm (n Int64) ENGINE={table_engine} {table_engine_params};"
)
2024-06-14 12:31:52 +00:00
2024-06-27 07:37:23 +00:00
test_table_uuid = node.query(
"SELECT uuid FROM system.tables WHERE table='test_table'"
2024-06-27 08:28:35 +00:00
).rstrip("\n")
2024-06-27 07:37:23 +00:00
test_table_metadata_path = node.query(
"SELECT metadata_path FROM system.tables WHERE table='test_table'"
2024-06-27 08:28:35 +00:00
).rstrip("\n")
2024-06-27 07:37:23 +00:00
test_table_perm_uuid = node.query(
"SELECT uuid FROM system.tables WHERE table='test_table_perm'"
2024-06-27 08:28:35 +00:00
).rstrip("\n")
2024-06-27 07:37:23 +00:00
test_table_perm_metadata_path = node.query(
"SELECT metadata_path FROM system.tables WHERE table='test_table_perm'"
2024-06-27 08:28:35 +00:00
).rstrip("\n")
2024-06-26 15:39:16 +00:00
2024-07-03 12:12:09 +00:00
assert "" == node.query(
f"SELECT * FROM system.detached_tables WHERE database='{db_name}'"
)
2024-06-14 12:31:52 +00:00
2024-07-03 12:12:09 +00:00
node.query(
f"SET database_replicated_always_detach_permanently=1; DETACH TABLE {db_name}.test_table"
)
2024-07-03 11:36:04 +00:00
node.query(f"DETACH TABLE {db_name}.test_table_perm PERMANENTLY")
2024-06-14 12:31:52 +00:00
2024-07-03 11:36:04 +00:00
querry = f"SELECT database, table, is_permanently, uuid, metadata_path FROM system.detached_tables WHERE database='{db_name}' FORMAT Values"
2024-06-26 15:39:16 +00:00
result = node.query(querry)
2024-07-03 12:12:09 +00:00
2024-07-03 11:36:04 +00:00
if db_engine.startswith("Repl"):
expected_before_restart = f"('{db_name}','test_table',1,'{test_table_uuid}','{test_table_metadata_path}'),('{db_name}','test_table_perm',1,'{test_table_perm_uuid}','{test_table_perm_metadata_path}')"
else:
expected_before_restart = f"('{db_name}','test_table',0,'{test_table_uuid}','{test_table_metadata_path}'),('{db_name}','test_table_perm',1,'{test_table_perm_uuid}','{test_table_perm_metadata_path}')"
assert result == expected_before_restart
if db_engine.startswith("Lazy"):
return
2024-07-03 12:12:09 +00:00
2024-06-14 12:31:52 +00:00
node.restart_clickhouse()
2024-07-03 11:36:04 +00:00
if db_engine.startswith("Repl"):
expected_after_restart = expected_before_restart
else:
expected_after_restart = f"('{db_name}','test_table_perm',1,'{test_table_perm_uuid}','{test_table_perm_metadata_path}')"
2024-06-26 15:39:16 +00:00
result = node.query(querry)
2024-07-03 11:36:04 +00:00
assert result == expected_after_restart
2024-06-14 12:31:52 +00:00
node.restart_clickhouse()
2024-06-26 15:39:16 +00:00
result = node.query(querry)
2024-07-03 11:36:04 +00:00
assert result == expected_after_restart
node.query(f"DROP DATABASE {db_name}")