Merge pull request #16432 from CartoDB/bug/sc-246788/cc2-sync-failing-randomly-2

Log pg_locks when there is a timeout during a sync table importation
pull/16433/head^2
Moisés Calzado 2 years ago committed by GitHub
commit 3c643498ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -97,6 +97,7 @@ Development
- 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)
- Add AUTODETECT_SIZE_LIMIT to ogr2ogr process when guessing CSV file column types [#16431](https://github.com/CartoDB/cartodb/pull/16431)
- Log pg locks if there is any problem during a sync table import process [#16432](https://github.com/CartoDB/cartodb/pull/16432)
4.45.0 (2021-04-14)
-------------------

@ -11,7 +11,7 @@ module CartoDB
THE_GEOM = 'the_geom'.freeze
OVERWRITE_ERROR = 2013
def initialize(table_name, runner, database, user, overviews_creator, synchronization_id)
def initialize(table_name, runner, database, user, overviews_creator, synchronization_id, logger = nil)
@table_name = table_name
@runner = runner
@database = database
@ -25,6 +25,7 @@ module CartoDB
)
@error_code = nil
@synchronization_id = synchronization_id
@logger = logger
end
def run(&tracker)
@ -393,6 +394,18 @@ module CartoDB
end
rescue Exception => exception
if exception.message.include?('canceling statement due to statement timeout')
# Check if the table has any lock
lock = user.in_database(as: :superuser).fetch(%Q{
SELECT pid, state, usename, query, query_start
FROM pg_stat_activity
WHERE pid in (
SELECT pid FROM pg_locks l
JOIN pg_class t ON l.relation = t.oid
AND t.relkind = 'r'
WHERE t.relname IN ('#{table_name}')
);
}).first
@logger.append_and_store "Transaction timed out as the table is blocked by query #{lock[:query]}. Retrying in 60 seconds..." if @logger && lock.present?
sleep(60) # wait 60 seconds and retry the swap
database.transaction do
rename(table_name, temporary_name) if exists?(table_name)

@ -192,7 +192,7 @@ module CartoDB
database = user.in_database
overviews_creator = CartoDB::Importer2::Overviews.new(runner, user)
importer = CartoDB::Synchronization::Adapter.new(name, runner, database, user, overviews_creator, id)
importer = CartoDB::Synchronization::Adapter.new(name, runner, database, user, overviews_creator, id, @log)
importer.run
self.ran_at = Time.now

Loading…
Cancel
Save