From 8e53998dfe36f21bddef21d20bab4555e55079a8 Mon Sep 17 00:00:00 2001 From: Juan Pardo Date: Thu, 17 Aug 2023 17:55:25 +0200 Subject: [PATCH] Fixed cloning empty partitioned table (#543) * Fixed cloning empty partitioned table --- CHANGES.rst | 3 +++ crate/operator/restore_backup.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9793d321..909841de 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------- diff --git a/crate/operator/restore_backup.py b/crate/operator/restore_backup.py index efb5c78f..65812a6c 100644 --- a/crate/operator/restore_backup.py +++ b/crate/operator/restore_backup.py @@ -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 " @@ -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." )