Skip to content

Commit

Permalink
Merge pull request #401 from MasahikoSawada/fix_tx_error_in_lock_acce…
Browse files Browse the repository at this point in the history
…ss_share

Use savepoints when retrying to take AccessShareLock.
  • Loading branch information
MasahikoSawada authored May 21, 2024
2 parents f3e6353 + a1e4987 commit f89c261
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/pg_repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,8 @@ kill_ddl(PGconn *conn, Oid relid, bool terminate)
/*
* Try to acquire an ACCESS SHARE table lock, avoiding deadlocks and long
* waits by killing off other sessions which may be stuck trying to obtain
* an ACCESS EXCLUSIVE lock.
* an ACCESS EXCLUSIVE lock. This function assumes that the transaction
* on "conn" already started.
*
* Arguments:
*
Expand All @@ -1801,6 +1802,8 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name)
PGresult *res;
int wait_msec;

pgut_command(conn, "SAVEPOINT repack_sp1", 0, NULL);

duration = time(NULL) - start;

/* Cancel queries unconditionally, i.e. don't bother waiting
Expand Down Expand Up @@ -1834,7 +1837,7 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name)
{
/* retry if lock conflicted */
CLEARPGRES(res);
pgut_rollback(conn);
pgut_command(conn, "ROLLBACK TO SAVEPOINT repack_sp1", 0, NULL);
continue;
}
else
Expand Down

0 comments on commit f89c261

Please sign in to comment.