2024-05-31 12:42:01 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
import time
|
|
|
|
|
|
|
|
import minio
|
2024-09-27 10:19:39 +00:00
|
|
|
import pytest
|
2024-05-31 12:42:01 +00:00
|
|
|
|
2024-09-27 10:19:39 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
2024-05-31 12:42:01 +00:00
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.add_instance(
|
|
|
|
"node1",
|
|
|
|
main_configs=["configs/storage_conf.xml"],
|
|
|
|
image="clickhouse/clickhouse-server",
|
|
|
|
with_minio=True,
|
|
|
|
tag="24.1",
|
|
|
|
stay_alive=True,
|
|
|
|
with_installed_binary=True,
|
|
|
|
)
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2024-05-31 12:51:02 +00:00
|
|
|
|
2024-05-31 12:42:01 +00:00
|
|
|
def test_bc_compatibility(started_cluster):
|
|
|
|
node1 = cluster.instances["node1"]
|
2024-05-31 12:51:02 +00:00
|
|
|
node1.query(
|
|
|
|
"""
|
2024-05-31 12:42:01 +00:00
|
|
|
CREATE TABLE test_ttl_table (
|
|
|
|
generation UInt64,
|
|
|
|
date_key DateTime,
|
|
|
|
number UInt64,
|
|
|
|
text String,
|
|
|
|
expired DateTime DEFAULT now()
|
|
|
|
)
|
|
|
|
ENGINE=MergeTree
|
|
|
|
ORDER BY (generation, date_key)
|
|
|
|
PARTITION BY toMonth(date_key)
|
|
|
|
TTL expired + INTERVAL 20 SECONDS TO DISK 's3'
|
|
|
|
SETTINGS storage_policy = 's3';
|
2024-05-31 12:51:02 +00:00
|
|
|
"""
|
|
|
|
)
|
2024-05-31 12:42:01 +00:00
|
|
|
|
2024-05-31 12:51:02 +00:00
|
|
|
node1.query(
|
|
|
|
"""
|
2024-05-31 12:42:01 +00:00
|
|
|
INSERT INTO test_ttl_table (
|
|
|
|
generation,
|
|
|
|
date_key,
|
|
|
|
number,
|
|
|
|
text
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
1,
|
|
|
|
toDateTime('2000-01-01 00:00:00') + rand(number) % 365 * 86400,
|
|
|
|
number,
|
|
|
|
toString(number)
|
|
|
|
FROM numbers(10000);
|
2024-05-31 12:51:02 +00:00
|
|
|
"""
|
|
|
|
)
|
2024-05-31 12:42:01 +00:00
|
|
|
|
2024-05-31 12:51:02 +00:00
|
|
|
disks = (
|
|
|
|
node1.query(
|
|
|
|
"""
|
2024-05-31 12:42:01 +00:00
|
|
|
SELECT distinct disk_name
|
|
|
|
FROM system.parts
|
|
|
|
WHERE table = 'test_ttl_table'
|
2024-05-31 12:51:02 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
.strip()
|
|
|
|
.split("\n")
|
|
|
|
)
|
2024-05-31 12:42:01 +00:00
|
|
|
print("Disks before", disks)
|
|
|
|
|
|
|
|
assert len(disks) == 1
|
|
|
|
assert disks[0] == "default"
|
|
|
|
|
|
|
|
node1.restart_with_latest_version()
|
|
|
|
|
|
|
|
for _ in range(60):
|
2024-05-31 12:51:02 +00:00
|
|
|
disks = (
|
|
|
|
node1.query(
|
|
|
|
"""
|
2024-05-31 12:42:01 +00:00
|
|
|
SELECT distinct disk_name
|
|
|
|
FROM system.parts
|
|
|
|
WHERE table = 'test_ttl_table'
|
2024-05-31 12:51:02 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
.strip()
|
|
|
|
.split("\n")
|
|
|
|
)
|
2024-05-31 12:42:01 +00:00
|
|
|
print("Disks after", disks)
|
|
|
|
if "s3" in disks:
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
assert "s3" in disks
|