Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed cloning empty partitioned table #543

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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