207207"""
208208)
209209
210+ KILL_RUNNING_FREEZE_SQL = strip_query (
211+ """
212+ KILL QUERY WHERE query_kind='Alter' AND user='{user}' AND query ilike '%ALTER TABLE%FREEZE%'
213+ """
214+ )
215+
210216DROP_TABLE_IF_EXISTS_SQL = strip_query (
211217 """
212218 DROP TABLE IF EXISTS `{db_name}`.`{table_name}` NO DELAY
@@ -586,6 +592,14 @@ def attach_table(self, table: Union[TableMetadata, Table]) -> None:
586592
587593 self ._ch_client .query (query_sql )
588594
595+ def kill_old_freeze_queries (self ):
596+ """
597+ Collect all freeze queries from prev backup and kill them all.
598+ """
599+ self ._ch_client .query (
600+ KILL_RUNNING_FREEZE_SQL .format (user = self ._ch_ctl_config ["user" ])
601+ )
602+
589603 def freeze_table (
590604 self ,
591605 backup_name : str ,
@@ -598,6 +612,12 @@ def freeze_table(
598612 # Table has no partitions or created with deprecated syntax.
599613 # FREEZE PARTITION ID with deprecated syntax throws segmentation fault in CH.
600614 freeze_by_partitions = threads > 0 and "PARTITION BY" in table .create_statement
615+
616+ query_settings = None
617+ # Since https://github.com/ClickHouse/ClickHouse/pull/75016
618+ if self .ch_version_ge ("25.2" ):
619+ query_settings = {"max_execution_time" : self ._freeze_timeout }
620+
601621 if freeze_by_partitions :
602622 with ThreadExecPool (max (1 , threads )) as pool :
603623 if freeze_by_partitions :
@@ -613,6 +633,7 @@ def freeze_table(
613633 f'Freeze partition "{ partition } "' ,
614634 self ._ch_client .query ,
615635 query_sql ,
636+ settings = query_settings ,
616637 timeout = self ._freeze_timeout ,
617638 should_retry = False ,
618639 new_session = True ,
@@ -629,6 +650,7 @@ def freeze_table(
629650 )
630651 self ._ch_client .query (
631652 query_sql ,
653+ settings = query_settings ,
632654 timeout = self ._freeze_timeout ,
633655 should_retry = False ,
634656 new_session = True ,
0 commit comments