Skip to content

Commit

Permalink
Use partitions list for reattach
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailBurdukov committed Sep 26, 2024
1 parent 5ad082b commit d5afbe4
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions ch_tools/chadmin/cli/partition_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ch_tools.common import logging
from ch_tools.common.cli.formatting import print_response
from ch_tools.common.cli.parameters import BytesParamType

import json

@group("partition", cls=Chadmin)
def partition_group():
Expand Down Expand Up @@ -397,6 +397,12 @@ def detach_partitions_command(
type=int,
help="Limit the max number of partitions to reattach in the output.",
),
option(
"--use-partition-list-from-json",
default=None,
type=str,
help="Use list of partitions instead of calculating the .",
),
constraint=RequireAtLeast(1),
)
@option("-k", "--keep-going", is_flag=True, help="Do not stop on the first error.")
Expand Down Expand Up @@ -433,6 +439,7 @@ def reattach_partitions_command(
keep_going,
limit_errors,
dry_run,
use_partition_list_from_json,
):
"""Perform sequential attach and detach of one or several partitions."""

Expand All @@ -445,23 +452,27 @@ def _table_formatter(partition):
)
)

partitions = get_partitions(
ctx,
database,
table,
partition_id=partition_id,
min_partition_id=min_partition_id,
max_partition_id=max_partition_id,
disk_name=disk_name,
merging=merging,
mutating=mutating,
has_replication_tasks=has_replication_tasks,
min_replication_task_postpone_count=min_replication_task_postpone_count,
max_replication_task_postpone_count=max_replication_task_postpone_count,
replication_task_exception=replication_task_exception,
limit=limit,
format_="JSON",
)["data"]
if use_partition_list_from_json:
with open(use_partition_list_from_json,'r') as json_file:
partitions = json.load(json_file)["data"]
else:
partitions = get_partitions(
ctx,
database,
table,
partition_id=partition_id,
min_partition_id=min_partition_id,
max_partition_id=max_partition_id,
disk_name=disk_name,
merging=merging,
mutating=mutating,
has_replication_tasks=has_replication_tasks,
min_replication_task_postpone_count=min_replication_task_postpone_count,
max_replication_task_postpone_count=max_replication_task_postpone_count,
replication_task_exception=replication_task_exception,
limit=limit,
format_="JSON",
)["data"]

error_count = 0
failed_partitions = []
Expand Down

0 comments on commit d5afbe4

Please sign in to comment.