Skip to content

Commit

Permalink
Use alter_table_timeout config option in part manipulation commands (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Burmak committed Apr 26, 2024
1 parent d0db081 commit 34f9a26
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ch_tools/chadmin/internal/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,40 +224,45 @@ def attach_part(ctx, database, table, part_name, dry_run=False):
"""
Attach the specified data part.
"""
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"]
query = f"ALTER TABLE `{database}`.`{table}` ATTACH PART '{part_name}'"
execute_query(ctx, query, timeout=300, format_=None, echo=True, dry_run=dry_run)
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run)


def detach_part(ctx, database, table, part_name, dry_run=False):
"""
Detach the specified data part.
"""
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"]
query = f"ALTER TABLE `{database}`.`{table}` DETACH PART '{part_name}'"
execute_query(ctx, query, timeout=300, format_=None, echo=True, dry_run=dry_run)
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run)


def move_part(ctx, database, table, part_name, new_disk_name, dry_run=False):
"""
Move the specified data part.
"""
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"]
query = f"ALTER TABLE `{database}`.`{table}` MOVE PART '{part_name}' TO DISK '{new_disk_name}'"
execute_query(ctx, query, timeout=600, format_=None, echo=True, dry_run=dry_run)
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run)


def drop_part(ctx, database, table, part_name, dry_run=False):
"""
Drop the specified data part.
"""
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"]
query = f"ALTER TABLE `{database}`.`{table}` DROP PART '{part_name}'"
execute_query(ctx, query, timeout=300, format_=None, echo=True, dry_run=dry_run)
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run)


def drop_detached_part(ctx, database, table, part_name, dry_run=False):
"""
Drop the specified detached data part.
"""
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"]
query = f"ALTER TABLE `{database}`.`{table}` DROP DETACHED PART '{part_name}'"
execute_query(ctx, query, timeout=300, format_=None, echo=True, dry_run=dry_run)
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run)


def list_part_log(
Expand Down

0 comments on commit 34f9a26

Please sign in to comment.