ClickHouse/tests/integration/test_old_parts_finally_removed/test.py

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

88 lines
2.2 KiB
Python
Raw Normal View History

2022-05-09 13:21:21 +00:00
#!/usr/bin/env python3
import os
import time
import helpers.client as client
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance("node1", with_zookeeper=True)
2022-05-09 17:03:17 +00:00
2022-05-09 13:21:21 +00:00
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
except Exception as ex:
print(ex)
finally:
cluster.shutdown()
def test_part_finally_removed(started_cluster):
2022-05-09 17:03:17 +00:00
node1.query(
"CREATE TABLE drop_outdated_part (Key UInt64) ENGINE = ReplicatedMergeTree('/table/d', '1') ORDER BY tuple() SETTINGS old_parts_lifetime=10, cleanup_delay_period=10, cleanup_delay_period_random_add=1"
)
2022-05-09 13:21:21 +00:00
node1.query("INSERT INTO drop_outdated_part VALUES (1)")
node1.query("OPTIMIZE TABLE drop_outdated_part FINAL")
2022-05-09 17:03:17 +00:00
node1.exec_in_container(
[
"bash",
"-c",
"chown -R root:root /var/lib/clickhouse/data/default/drop_outdated_part/all_0_0_0",
],
privileged=True,
user="root",
)
2022-05-09 13:21:21 +00:00
2022-05-09 17:03:17 +00:00
node1.query(
"ALTER TABLE drop_outdated_part MODIFY SETTING old_parts_lifetime=1, cleanup_delay_period=1, cleanup_delay_period_random_add=1"
)
2022-05-09 13:21:21 +00:00
for i in range(60):
if node1.contains_in_log("Cannot quickly remove directory"):
break
time.sleep(0.5)
2022-05-09 17:03:17 +00:00
node1.exec_in_container(
[
"bash",
"-c",
f"chown -R {os.getuid()}:{os.getgid()} /var/lib/clickhouse/data/default/drop_outdated_part/*",
],
privileged=True,
user="root",
)
2022-05-09 13:21:21 +00:00
for i in range(60):
2022-05-09 17:03:17 +00:00
if (
node1.query(
"SELECT count() from system.parts WHERE table = 'drop_outdated_part'"
)
== "1\n"
):
out = node1.exec_in_container(
[
"bash",
"-c",
"ls /var/lib/clickhouse/data/default/drop_outdated_part | grep '_' | grep 'all'",
],
privileged=True,
user="root",
)
assert (
"all_0_0_0" not in out
), f"Print found part which must be deleted: {out}"
2022-05-09 13:21:21 +00:00
break
time.sleep(0.5)