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 remove orphaned #285

Merged
merged 3 commits into from
Feb 3, 2025
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
11 changes: 9 additions & 2 deletions ch_tools/chadmin/cli/data_store_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
S3ObjectLocalInfo,
S3ObjectLocalMetaData,
)
from ch_tools.chadmin.internal.system import get_version
from ch_tools.chadmin.internal.utils import execute_query, remove_from_disk
from ch_tools.common import logging
from ch_tools.common.cli.formatting import print_response
Expand Down Expand Up @@ -258,6 +259,7 @@ def cleanup_data_dir(
"disk": disk,
"path_to_disk": path_to_disk,
"disks_config_path": disk_config_path,
"ch_version": get_version(ctx),
},
)
tasks.append(task)
Expand All @@ -276,15 +278,20 @@ def remove_orphaned_sql_object_metadata(data):
data["deleted"] = "Yes"


def remove_orphaned_sql_object_full(data, disk, path_to_disk, disks_config_path):
def remove_orphaned_sql_object_full(
data, disk, path_to_disk, ch_version, disks_config_path
):

path = data["path"]

if not path.startswith(path_to_disk):
raise RuntimeError(f"Path {path} on fs does not math with disk {disk}")
relative_path_on_disk = path[len(path_to_disk) + 1 :]
retcode, stderr = remove_from_ch_disk(
disk, relative_path_on_disk, disks_config_path
disk=disk,
path=relative_path_on_disk,
ch_version=ch_version,
disk_config_path=disks_config_path,
k-morozov marked this conversation as resolved.
Show resolved Hide resolved
)
if retcode:
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion ch_tools/chadmin/internal/clickhouse_disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def make_ch_disks_config(disk: str) -> str:


def remove_from_ch_disk(
disk: str, path: str, ch_version: 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}"
if match_str_ch_version(ch_version, "24.7"):
Expand Down
9 changes: 9 additions & 0 deletions ch_tools/chadmin/internal/system.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import re

from click import Context
from pkg_resources import parse_version

from ch_tools.chadmin.internal.utils import clickhouse_client


def validate_version(version: str) -> None:
pattern = r"^\d{2}\.\d{2}\.\d+\.\d+$"

assert not re.match(pattern, version), f"version={version} has broken format"


def get_version(ctx: Context) -> str:
"""
Get ClickHouse version.
Expand All @@ -22,4 +30,5 @@ def match_str_ch_version(version: str, min_version: str) -> bool:
"""
Returns True if ClickHouse version >= min_version.
"""
validate_version(version)
return parse_version(version) >= parse_version(min_version)
Loading