From c037445edf03237e80f7a482a0b4f367e5082f2f Mon Sep 17 00:00:00 2001 From: MikhailBurdukov Date: Tue, 16 Jul 2024 15:31:07 +0000 Subject: [PATCH] Review fix --- ch_backup/clickhouse/control.py | 7 ++++++- ch_backup/clickhouse/models.py | 4 ++-- ch_backup/logic/table.py | 9 +++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ch_backup/clickhouse/control.py b/ch_backup/clickhouse/control.py index 2adcd1b1..c01c88b1 100644 --- a/ch_backup/clickhouse/control.py +++ b/ch_backup/clickhouse/control.py @@ -62,7 +62,6 @@ SELECT database, name, - create_table_query, engine, create_table_query FROM system.tables @@ -566,6 +565,12 @@ def get_table( Get table by name, returns None if no table has found. """ tables = self.get_tables(db_name, [table_name], short_query) + + if len(tables) > 1: + raise RuntimeError( + f"Found several tables, when expected to find single table: database {db_name}, table {table_name}" + ) + return tables[0] if len(tables) == 1 else None def does_table_exist(self, db_name: str, table_name: str) -> bool: diff --git a/ch_backup/clickhouse/models.py b/ch_backup/clickhouse/models.py index e29ae606..10679373 100644 --- a/ch_backup/clickhouse/models.py +++ b/ch_backup/clickhouse/models.py @@ -87,14 +87,14 @@ def is_replicated(self) -> bool: """ Return True if table engine belongs to replicated merge tree table engine family, or False otherwise. """ - return self.is_merge_tree() and self.engine.find("Replicated") != -1 + return Table.engine_is_replicated(self.engine) @staticmethod def engine_is_replicated(engine: str) -> bool: """ A static method for determining whether an engine is replicated or not. """ - return Table("", "", engine, [], [], "", "", None).is_replicated() + return "MergeTree" in engine and "Replicated" in engine def is_merge_tree(self) -> bool: """ diff --git a/ch_backup/logic/table.py b/ch_backup/logic/table.py index 868ff24c..c57f1f12 100644 --- a/ch_backup/logic/table.py +++ b/ch_backup/logic/table.py @@ -651,16 +651,17 @@ def _restore_data( maybe_table_short = context.ch_ctl.get_table( table_meta.database, table_meta.name, short_query=True ) - assert ( - maybe_table_short is not None - ), f"Table not found {table_meta.database}.{table_meta.name}" + if not maybe_table_short: + raise ClickhouseBackupError( + f"Table not found {table_meta.database}.{table_meta.name}" + ) # 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.', + 'Skip table "{}.{}" data restore, because it is not MergeTree family.', table_meta.database, table_meta.name, )