Skip to content

Commit

Permalink
fix clickhouse disks in 24.7
Browse files Browse the repository at this point in the history
  • Loading branch information
k-morozov committed Aug 14, 2024
1 parent 2455a54 commit 2fe6c04
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 10 additions & 2 deletions ch_tools/chadmin/internal/clickhouse_disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 = 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(
Expand All @@ -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)
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

0 comments on commit 2fe6c04

Please sign in to comment.