Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix using clickhouse disks in 24.7 for drop detached table #221

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ch_tools/chadmin/internal/clickhouse_disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import xmltodict

from ch_tools.chadmin.internal.system import match_str_ch_version
from ch_tools.common import logging
from ch_tools.common.clickhouse.config import ClickhouseConfig

Expand Down Expand Up @@ -34,9 +35,14 @@ def make_ch_disks_config(disk: str) -> str:


def remove_from_ch_disk(
disk: str, path: str, disk_config_path: Optional[str] = None
disk: str, path: str, ch_version: str = "", disk_config_path: Optional[str] = None
) -> Tuple[int, bytes]:
cmd = f"clickhouse-disks { '-C ' + disk_config_path if disk_config_path else ''} --disk {disk} remove {path}"
cmd = f"clickhouse-disks {'-C ' + disk_config_path if disk_config_path else ''} --disk {disk}"
if match_str_ch_version(ch_version, "24.7"):
cmd += f' --query "remove {path} --recursive"'
else:
cmd += f" remove {path}"

logging.info("Run : {}", cmd)

proc = subprocess.run(
Expand All @@ -46,4 +52,10 @@ def remove_from_ch_disk(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

logging.info(
"clickhouse-disks remove command has finished: retcode {}, stderr: {}",
proc.returncode,
proc.stderr.decode(),
)
return (proc.returncode, proc.stderr)
9 changes: 8 additions & 1 deletion ch_tools/chadmin/internal/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ def match_ch_version(ctx: Context, min_version: str) -> bool:
"""
Returns True if ClickHouse version >= min_version.
"""
return parse_version(get_version(ctx)) >= parse_version(min_version)
return match_str_ch_version(get_version(ctx), min_version)


def match_str_ch_version(version: str, min_version: str) -> bool:
"""
Returns True if ClickHouse version >= min_version.
"""
return parse_version(version) >= parse_version(min_version)
5 changes: 4 additions & 1 deletion ch_tools/chadmin/internal/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
make_ch_disks_config,
remove_from_ch_disk,
)
from ch_tools.chadmin.internal.system import get_version
from ch_tools.chadmin.internal.utils import execute_query, remove_from_disk
from ch_tools.chadmin.internal.zookeeper import clean_zk_metadata_for_hosts
from ch_tools.common import logging
Expand Down Expand Up @@ -352,7 +353,7 @@ def _is_should_use_ch_disk_remover(table_data_path: str, disk_type: str) -> bool


def _remove_table_data_from_disk(
table_uuid: str, disk_name: str, disk_type: str
table_uuid: str, disk_name: str, disk_type: str, ch_version: str
) -> None:
logging.info(
"_remove_table_data_from_disk: UUID={}, disk={}",
Expand Down Expand Up @@ -380,6 +381,7 @@ def _remove_table_data_from_disk(
disk=disk_name,
path=table_data_path,
disk_config_path=disk_config_path,
ch_version=ch_version,
)
if code:
raise RuntimeError(
Expand Down Expand Up @@ -418,6 +420,7 @@ def delete_detached_table(ctx, database_name, table_name):
table_uuid=table_metadata.table_uuid,
disk_name=disk_name,
disk_type=disk_type,
ch_version=get_version(ctx),
)

if table_metadata.table_engine.is_table_engine_replicated():
Expand Down
Loading