Skip to content

Commit 16a1b13

Browse files
committed
skip gc tables handling if there is no gc table to restore
1 parent ac3f819 commit 16a1b13

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

crate/operator/restore_backup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,11 @@ async def set_gc_tables(
11861186

11871187
if restore_type == SnapshotRestoreType.TABLES.value and tables is not None:
11881188
gc_tables = [table for table in tables if table.startswith("gc.")]
1189+
1190+
# There is no gc table to restore, no need to proceed further
1191+
if not gc_tables:
1192+
return
1193+
11891194
tables_str = ",".join(f"'{table}'" for table in gc_tables)
11901195
where_stmt = f"t IN ({tables_str})"
11911196
else:
@@ -1237,7 +1242,7 @@ async def rename_duplicated_tables(self):
12371242
If the snapshot contains grand central tables, rename them if they exist
12381243
in the cluster in order to recreate the new ones from the snapshot.
12391244
"""
1240-
if not self.gc_tables:
1245+
if not self.is_enabled():
12411246
return
12421247

12431248
try:
@@ -1259,7 +1264,7 @@ async def restore_tables(self):
12591264
If the restore operation failed, rename back the gc tables
12601265
to their original names.
12611266
"""
1262-
if not self.gc_tables:
1267+
if not self.is_enabled():
12631268
return
12641269

12651270
try:
@@ -1280,7 +1285,7 @@ async def cleanup_tables(self):
12801285
"""
12811286
After a successful restore, the temporary renamed gc tables can be dropped.
12821287
"""
1283-
if not self.gc_tables:
1288+
if not self.is_enabled():
12841289
return
12851290

12861291
try:

tests/test_restore_backup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,10 @@ async def test_set_gc_tables(
11001100
replace_gc_tables_data
11011101
)
11021102

1103-
fetch_response = [(t,) for t in tables_with_schema]
1104-
mock_cursor.fetchall.return_value = fetch_response if gc_enabled else []
1103+
mock_cursor.fetchall.side_effect = [
1104+
[(t,) for t in tables_with_schema] if gc_enabled else [],
1105+
[(t,) for t in tables] if gc_enabled else [],
1106+
]
11051107

11061108
await gc_tables_cls.set_gc_tables(restore_type.value, tables_with_schema)
11071109

@@ -1118,6 +1120,8 @@ async def test_set_gc_tables(
11181120
(repository, snapshot),
11191121
),
11201122
]
1123+
if gc_enabled:
1124+
stmts.append(mock.call('SHOW TABLES FROM "gc";'))
11211125
assert gc_tables_cls.gc_tables == (tables_with_schema if gc_enabled else [])
11221126
elif restore_type == SnapshotRestoreType.TABLES:
11231127
stmts = [
@@ -1132,6 +1136,8 @@ async def test_set_gc_tables(
11321136
(repository, snapshot),
11331137
),
11341138
]
1139+
if gc_enabled:
1140+
stmts.append(mock.call('SHOW TABLES FROM "gc";'))
11351141
assert gc_tables_cls.gc_tables == (tables_with_schema if gc_enabled else [])
11361142
else:
11371143
stmts = []

0 commit comments

Comments
 (0)