Skip to content

Commit

Permalink
Prevent deadlock when importing database (#8648)
Browse files Browse the repository at this point in the history
* lock all tables at beginning of transaction to avoid deadlocks

* fix lock statement format
  • Loading branch information
lmossman committed Dec 8, 2021
1 parent 07287ca commit 973c043
Showing 1 changed file with 4 additions and 0 deletions.
Expand Up @@ -640,6 +640,10 @@ private void importDatabase(final String airbyteVersion,
if (!data.isEmpty()) {
createSchema(BACKUP_SCHEMA);
jobDatabase.transaction(ctx -> {
// obtain locks on all tables first, to prevent deadlocks
for (final JobsDatabaseSchema tableType : data.keySet()) {
ctx.execute(String.format("LOCK TABLE %s IN ACCESS EXCLUSIVE MODE", tableType.name()));
}
for (final JobsDatabaseSchema tableType : data.keySet()) {
if (!incrementalImport) {
truncateTable(ctx, targetSchema, tableType.name(), BACKUP_SCHEMA);
Expand Down

0 comments on commit 973c043

Please sign in to comment.