Skip to content

Commit

Permalink
Fix for 23.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailBurdukov committed Jul 16, 2024
1 parent 9e8912f commit f00935b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
36 changes: 8 additions & 28 deletions ch_backup/clickhouse/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
SELECT
database,
name,
create_table_query,
engine,
create_table_query
FROM system.tables
WHERE ({db_condition})
Expand All @@ -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()
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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 []
),
Expand Down
32 changes: 19 additions & 13 deletions ch_backup/logic/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f00935b

Please sign in to comment.