2022-06-07 15:41:14 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-09-27 10:19:39 +00:00
|
|
|
import os
|
|
|
|
|
2022-06-07 15:41:14 +00:00
|
|
|
import pytest
|
2024-09-27 10:19:39 +00:00
|
|
|
|
2022-06-07 15:41:14 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
from helpers.test_tools import assert_logs_contain_with_retry
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node1 = cluster.add_instance("node1", with_zookeeper=True, stay_alive=True)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
for i, node in enumerate((node1,)):
|
|
|
|
node_name = "node" + str(i + 1)
|
|
|
|
node.query(
|
|
|
|
"""
|
|
|
|
CREATE TABLE test_table(date Date, id UInt32, dummy UInt32)
|
|
|
|
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test_table', '{}')
|
|
|
|
PARTITION BY date ORDER BY id
|
|
|
|
""".format(
|
|
|
|
node_name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2022-06-07 15:58:53 +00:00
|
|
|
|
2022-06-07 15:41:14 +00:00
|
|
|
def test_old_dirs_cleanup(start_cluster):
|
|
|
|
node1.query("INSERT INTO test_table VALUES (toDate('2020-01-01'), 1, 10)")
|
|
|
|
assert node1.query("SELECT count() FROM test_table") == "1\n"
|
|
|
|
|
|
|
|
node1.stop_clickhouse()
|
|
|
|
|
|
|
|
node1.exec_in_container(
|
|
|
|
[
|
|
|
|
"bash",
|
|
|
|
"-c",
|
2022-06-07 15:58:53 +00:00
|
|
|
"mv /var/lib/clickhouse/data/default/test_table/20200101_0_0_0 /var/lib/clickhouse/data/default/test_table/delete_tmp_20200101_0_0_0",
|
2022-06-07 15:41:14 +00:00
|
|
|
],
|
|
|
|
privileged=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
node1.start_clickhouse()
|
|
|
|
|
|
|
|
result = node1.exec_in_container(
|
2022-06-07 15:58:53 +00:00
|
|
|
["bash", "-c", "ls /var/lib/clickhouse/data/default/test_table/"],
|
2022-06-07 15:41:14 +00:00
|
|
|
privileged=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Replaced empty part
|
|
|
|
assert "20200101_0_0_0" in result
|
|
|
|
assert node1.query("SELECT count() FROM test_table") == "0\n"
|
|
|
|
|
|
|
|
assert_logs_contain_with_retry(node1, "Removing temporary directory")
|
2022-06-07 15:58:32 +00:00
|
|
|
assert_logs_contain_with_retry(node1, "delete_tmp_20200101_0_0_0")
|