From f00935b8402dbba5f533e1c141f18ddf1ae1f154 Mon Sep 17 00:00:00 2001 From: MikhailBurdukov Date: Tue, 16 Jul 2024 08:42:11 +0000 Subject: [PATCH] Fix for 23.3 --- ch_backup/clickhouse/control.py | 36 ++++++++------------------------- ch_backup/logic/table.py | 32 +++++++++++++++++------------ 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/ch_backup/clickhouse/control.py b/ch_backup/clickhouse/control.py index d51474c5..2adcd1b1 100644 --- a/ch_backup/clickhouse/control.py +++ b/ch_backup/clickhouse/control.py @@ -62,6 +62,8 @@ SELECT database, name, + create_table_query, + engine, create_table_query FROM system.tables WHERE ({db_condition}) @@ -71,23 +73,6 @@ """ ) -GET_TABLE_SQL = strip_query( - """ - SELECT - database, - name, - engine, - engine_full, - create_table_query, - data_paths, - metadata_path, - uuid - FROM system.tables - WHERE database = '{db_name}' AND name = '{table_name}' - FORMAT JSON -""" -) - CHECK_TABLE_SQL = strip_query( """ SELECT count() @@ -574,19 +559,14 @@ def get_tables( return result - def get_table(self, db_name: str, table_name: str) -> Optional[Table]: + def get_table( + self, db_name: str, table_name: str, short_query: bool = False + ) -> Optional[Table]: """ Get table by name, returns None if no table has found. """ - query_sql = GET_TABLE_SQL.format( - db_name=escape(db_name), table_name=escape(table_name) - ) - - result = self._ch_client.query(query_sql)["data"] - if result: - return self._make_table(result[0]) - - return None + tables = self.get_tables(db_name, [table_name], short_query) + return tables[0] if len(tables) == 1 else None def does_table_exist(self, db_name: str, table_name: str) -> bool: """ @@ -922,7 +902,7 @@ def _make_table(self, record: dict) -> Table: engine=record.get("engine", None), disks=list(self._disks.values()), data_paths=( - record.get("data_paths", None) + record.get("data_paths", []) if "MergeTree" in record.get("engine", "") else [] ), diff --git a/ch_backup/logic/table.py b/ch_backup/logic/table.py index 7bccc27a..868ff24c 100644 --- a/ch_backup/logic/table.py +++ b/ch_backup/logic/table.py @@ -648,27 +648,33 @@ def _restore_data( for table_meta in tables: cloud_storage_parts = [] try: - logging.debug( - 'Running table "{}.{}" data restore', - table_meta.database, - table_meta.name, - ) - - maybe_table = context.ch_ctl.get_table( - table_meta.database, table_meta.name + maybe_table_short = context.ch_ctl.get_table( + table_meta.database, table_meta.name, short_query=True ) assert ( - maybe_table is not None + maybe_table_short is not None ), f"Table not found {table_meta.database}.{table_meta.name}" - table: Table = maybe_table - if not table.is_merge_tree(): + + # We have to check table engine on short Table version + # because some of columns might be inaccessbible, for old ch versions. + # Fix https://github.com/ClickHouse/ClickHouse/pull/55540 is pesented since 23.8. + if not maybe_table_short.is_merge_tree(): logging.debug( 'Skiptable "{}.{}" data restore, because it is not MergeTree like.', - table.database, - table.name, + table_meta.database, + table_meta.name, ) continue + logging.debug( + 'Running table "{}.{}" data restore', + table_meta.database, + table_meta.name, + ) + + table: Table = context.ch_ctl.get_table( + table_meta.database, table_meta.name + ) # type: ignore attach_parts = [] for part in table_meta.get_parts(): if context.restore_context.part_restored(part):