Skip to content

Commit

Permalink
Moved timeout for alter queries to config (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Burmak authored Feb 16, 2024
1 parent 0ea863d commit deeefdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 43 deletions.
52 changes: 10 additions & 42 deletions ch_tools/chadmin/internal/partition.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,46 @@
from ch_tools.chadmin.internal.utils import execute_query

DEFAULT_TIMEOUT = 600


def attach_partition(ctx, database, table, partition_id, dry_run=False):
"""
Attach the specified table partition.
"""
query = f"ALTER TABLE `{database}`.`{table}` ATTACH PARTITION ID '{partition_id}'"
execute_query(
ctx,
query,
timeout=DEFAULT_TIMEOUT,
format_=None,
echo=True,
dry_run=dry_run,
)
_execute_query(ctx, query, dry_run)


def detach_partition(ctx, database, table, partition_id, dry_run=False):
"""
Detach the specified table partition.
"""
query = f"ALTER TABLE `{database}`.`{table}` DETACH PARTITION ID '{partition_id}'"
execute_query(
ctx,
query,
timeout=DEFAULT_TIMEOUT,
format_=None,
echo=True,
dry_run=dry_run,
)
_execute_query(ctx, query, dry_run)


def drop_partition(ctx, database, table, partition_id, dry_run=False):
"""
Drop the specified table partition.
"""
query = f"ALTER TABLE `{database}`.`{table}` DROP PARTITION ID '{partition_id}'"
execute_query(
ctx,
query,
timeout=DEFAULT_TIMEOUT,
format_=None,
echo=True,
dry_run=dry_run,
)
_execute_query(ctx, query, dry_run)


def optimize_partition(ctx, database, table, partition_id, dry_run=False):
"""
Optimize the specified table partition.
"""
query = f"OPTIMIZE TABLE `{database}`.`{table}` PARTITION ID '{partition_id}'"
execute_query(
ctx,
query,
timeout=DEFAULT_TIMEOUT,
format_=None,
echo=True,
dry_run=dry_run,
)
_execute_query(ctx, query, dry_run)


def materialize_ttl_in_partition(ctx, database, table, partition_id, dry_run=False):
"""
Materialize TTL for the specified table partition.
"""
query = f"ALTER TABLE `{database}`.`{table}` MATERIALIZE TTL IN PARTITION ID '{partition_id}'"
execute_query(
ctx,
query,
timeout=DEFAULT_TIMEOUT,
format_=None,
echo=True,
dry_run=dry_run,
)
_execute_query(ctx, query, dry_run)


def _execute_query(ctx, query, dry_run):
timeout = ctx.obj["config"]["clickhouse"]["alter_table_timeout"]
execute_query(ctx, query, timeout=timeout, format_=None, echo=True, dry_run=dry_run)
3 changes: 2 additions & 1 deletion ch_tools/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"port": 8443,
"user": None,
"password": None,
"timeout": 60,
"settings": {},
"monitoring_user": None,
"monitoring_password": None,
"distributed_ddl_path": "/clickhouse/task_queue/ddl",
"timeout": 60,
"alter_table_timeout": 600,
},
"object_storage": {
"clean": {
Expand Down

0 comments on commit deeefdf

Please sign in to comment.