Skip to content

Commit

Permalink
Fixed cloning empty partitioned table (#543)
Browse files Browse the repository at this point in the history
* Fixed cloning empty partitioned table
  • Loading branch information
juanpardo authored Aug 17, 2023
1 parent f041483 commit 8e53998
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
Unreleased
----------

* Fixed a bug that made cloning/restoring an empty partitioned table report a failure
regardless of whether it succeeded or not.

2.30.2 (2023-08-10)
-------------------

Expand Down
12 changes: 11 additions & 1 deletion crate/operator/restore_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ async def shards_recovery_in_progress(
for t in tables:
(schema, table_name) = t.rsplit(".", 1)
try:
# If there is at least one shard, the table is not empty.
# We need to check that to ensure the operation does not fail while
# restoring empty partitioned tables.
await cursor.execute(
"SELECT id FROM sys.shards WHERE schema_name = %s "
"AND table_name = %s "
"LIMIT 1;",
(schema, table_name),
)
any_shard_exists = await cursor.fetchone()
await cursor.execute(
"SELECT id FROM sys.shards WHERE schema_name = %s "
"AND table_name = %s "
Expand All @@ -346,7 +356,7 @@ async def shards_recovery_in_progress(
)
shard_in_progress = await cursor.fetchone()

if not primary_shard_exists or shard_in_progress:
if any_shard_exists and (not primary_shard_exists or shard_in_progress):
logger.info(
f"Table {schema}.{table_name} was not restored successfully."
)
Expand Down

0 comments on commit 8e53998

Please sign in to comment.