From 21d1dd337fba6bccae9b7932cde7587ec6203a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Calzado?= Date: Tue, 26 Jul 2022 14:25:34 +0200 Subject: [PATCH 1/2] Handle timeout swaping tables during sync process --- app/models/synchronization/adapter.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/models/synchronization/adapter.rb b/app/models/synchronization/adapter.rb index c8d94ec4af..b71305d580 100644 --- a/app/models/synchronization/adapter.rb +++ b/app/models/synchronization/adapter.rb @@ -140,11 +140,7 @@ module CartoDB table_statements = @table_setup.generate_table_statements(schema, table_name) temporary_name = temporary_name_for(result.table_name) - database.transaction do - rename(table_name, temporary_name) if exists?(table_name) - drop(temporary_name) if exists?(temporary_name) - rename(result.table_name, table_name) - end + swap_tables(table_name, temporary_name, result) @table_setup.fix_oid(table_name) @table_setup.update_cdb_tablemetadata(table_name) @table_setup.run_table_statements(table_statements, @database) @@ -389,6 +385,25 @@ module CartoDB private + def swap_tables(table_name, temporary_name, result) + database.transaction do + rename(table_name, temporary_name) if exists?(table_name) + drop(temporary_name) if exists?(temporary_name) + rename(result.table_name, table_name) + end + rescue Exception => exception + if exception.message.include?('canceling statement due to statement timeout') + sleep(60) # wait 60 seconds and retry the swap + database.transaction do + rename(table_name, temporary_name) if exists?(table_name) + drop(temporary_name) if exists?(temporary_name) + rename(result.table_name, table_name) + end + else + raise exception + end + end + def valid_cartodb_id_candidate?(user, table_name, qualified_table_name, col_name) return false unless column_names(user, table_name).include?(col_name) user.transaction_with_timeout(statement_timeout: STATEMENT_TIMEOUT, as: :superuser) do |db| From 5e06df730d5bfcddd5e76864f36b559a721f718d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Calzado?= Date: Tue, 26 Jul 2022 14:28:35 +0200 Subject: [PATCH 2/2] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c74ac7abb5..ccc0e9cf8c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -95,6 +95,7 @@ Development - Fix duplicated attributions in datasets [#16384](https://github.com/CartoDB/cartodb/pull/16384) - Moving assets cdn domain from global.ssl.fastly.net to libs.cartocdn.com [#16399](https://github.com/CartoDB/cartodb/pull/16399) - Fix error while rolling back a user migration from one cloud to another [#16421](https://github.com/CartoDB/cartodb/pull/16421) +- Add retry if a timeout is thrown when swapping the tables related with a sync process [#16430](https://github.com/CartoDB/cartodb/pull/16430) 4.45.0 (2021-04-14) -------------------