diff --git a/ch_tools/chadmin/internal/clickhouse_disks.py b/ch_tools/chadmin/internal/clickhouse_disks.py index 111b8998..571b5eec 100644 --- a/ch_tools/chadmin/internal/clickhouse_disks.py +++ b/ch_tools/chadmin/internal/clickhouse_disks.py @@ -5,6 +5,7 @@ from ch_tools.common import logging from ch_tools.common.clickhouse.config import ClickhouseConfig +from ch_tools.chadmin.internal.system import match_str_ch_version CLICKHOUSE_PATH = "/var/lib/clickhouse" CLICKHOUSE_STORE_PATH = CLICKHOUSE_PATH + "/store" @@ -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 = None, 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 ch_version is None or not match_str_ch_version(ch_version, "24.7"): + cmd += f" remove {path}" + else: + cmd += f" --query \"remove {path} --recursive\"" + logging.info("Run : {}", cmd) proc = subprocess.run( @@ -46,4 +52,6 @@ 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) diff --git a/ch_tools/chadmin/internal/system.py b/ch_tools/chadmin/internal/system.py index f176ff46..6bd1c27e 100644 --- a/ch_tools/chadmin/internal/system.py +++ b/ch_tools/chadmin/internal/system.py @@ -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) diff --git a/ch_tools/chadmin/internal/table.py b/ch_tools/chadmin/internal/table.py index 8eff0da7..3409b31f 100644 --- a/ch_tools/chadmin/internal/table.py +++ b/ch_tools/chadmin/internal/table.py @@ -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 @@ -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={}", @@ -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( @@ -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():