2022-10-24 20:07:26 +00:00
|
|
|
# pylint: disable=global-statement
|
|
|
|
# pylint: disable=line-too-long
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node = cluster.add_instance(
|
|
|
|
"node",
|
|
|
|
main_configs=["configs/disk_s3.xml"],
|
|
|
|
with_minio=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2022-11-02 15:05:59 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"table_name,backup_name,storage_policy,min_bytes_for_wide_part",
|
|
|
|
[
|
|
|
|
pytest.param(
|
|
|
|
"compact", "backup_compact", "s3_backup_compact", int(1e9), id="compact"
|
|
|
|
),
|
|
|
|
pytest.param("wide", "backup_wide", "s3_backup_wide", int(0), id="wide"),
|
|
|
|
],
|
|
|
|
)
|
2022-11-17 18:26:40 +00:00
|
|
|
def test_attach_part(table_name, backup_name, storage_policy, min_bytes_for_wide_part):
|
2022-10-24 20:07:26 +00:00
|
|
|
node.query(
|
|
|
|
f"""
|
2022-11-02 15:05:59 +00:00
|
|
|
-- Catch any errors (NOTE: warnings are ok)
|
|
|
|
set send_logs_level='error';
|
|
|
|
|
2022-10-24 20:07:26 +00:00
|
|
|
-- BACKUP writes Ordinary like structure
|
|
|
|
set allow_deprecated_database_ordinary=1;
|
|
|
|
|
2022-11-02 15:05:59 +00:00
|
|
|
create database ordinary_db engine=Ordinary;
|
|
|
|
|
2022-12-05 12:29:31 +00:00
|
|
|
create table ordinary_db.{table_name} engine=MergeTree() order by key partition by part as select number%5 part, number key from numbers(100);
|
2022-10-24 20:07:26 +00:00
|
|
|
-- NOTE: name of backup ("backup") is significant.
|
2022-12-05 12:29:31 +00:00
|
|
|
backup table ordinary_db.{table_name} TO Disk('backup_disk_s3_plain', '{backup_name}') settings deduplicate_files=0;
|
2022-10-24 20:07:26 +00:00
|
|
|
|
2022-11-02 15:05:59 +00:00
|
|
|
drop table ordinary_db.{table_name};
|
2022-12-05 12:29:31 +00:00
|
|
|
attach table ordinary_db.{table_name} (part UInt8, key UInt64)
|
2022-11-02 15:05:59 +00:00
|
|
|
engine=MergeTree()
|
2022-12-05 12:29:31 +00:00
|
|
|
order by key partition by part
|
2022-11-02 15:05:59 +00:00
|
|
|
settings
|
|
|
|
min_bytes_for_wide_part={min_bytes_for_wide_part},
|
2022-12-05 12:29:31 +00:00
|
|
|
max_suspicious_broken_parts=0,
|
2022-11-02 15:05:59 +00:00
|
|
|
storage_policy='{storage_policy}';
|
2022-10-24 20:07:26 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2022-11-02 15:05:59 +00:00
|
|
|
assert int(node.query(f"select count() from ordinary_db.{table_name}")) == 100
|
|
|
|
|
|
|
|
node.query(
|
|
|
|
f"""
|
|
|
|
-- NOTE: DROP DATABASE cannot be done w/o this due to metadata leftovers
|
|
|
|
set force_remove_data_recursively_on_drop=1;
|
|
|
|
drop database ordinary_db sync;
|
|
|
|
"""
|
|
|
|
)
|