MCPcopy Create free account
hub / github.com/apache/cloudberry / LockErrorCleanup

Function LockErrorCleanup

src/backend/storage/lmgr/proc.c:880–945  ·  view source on GitHub ↗

* Cancel any pending wait for lock, when aborting a transaction, and revert * any strong lock count acquisition for a lock being acquired. * * (Normally, this would only happen if we accept a cancel/die * interrupt while waiting; but an ereport(ERROR) before or during the lock * wait is within the realm of possibility, too.) */

Source from the content-addressed store, hash-verified

878 * wait is within the realm of possibility, too.)
879 */
880void
881LockErrorCleanup(void)
882{
883 LWLock *partitionLock;
884 DisableTimeoutParams timeouts[2];
885
886 HOLD_INTERRUPTS();
887
888 AbortStrongLockAcquire();
889
890 /* Nothing to do if we weren't waiting for a lock */
891 if (lockAwaited == NULL)
892 {
893 RESUME_INTERRUPTS();
894 return;
895 }
896
897 /* Don't try to cancel resource locks.*/
898 if ((Gp_role == GP_ROLE_DISPATCH || IS_SINGLENODE()) && IsResQueueEnabled() &&
899 LOCALLOCK_LOCKMETHOD(*lockAwaited) == RESOURCE_LOCKMETHOD)
900 {
901 RESUME_INTERRUPTS();
902 return;
903 }
904
905 /*
906 * Turn off the deadlock and lock timeout timers, if they are still
907 * running (see ProcSleep). Note we must preserve the LOCK_TIMEOUT
908 * indicator flag, since this function is executed before
909 * ProcessInterrupts when responding to SIGINT; else we'd lose the
910 * knowledge that the SIGINT came from a lock timeout and not an external
911 * source.
912 */
913 timeouts[0].id = DEADLOCK_TIMEOUT;
914 timeouts[0].keep_indicator = false;
915 timeouts[1].id = LOCK_TIMEOUT;
916 timeouts[1].keep_indicator = true;
917 disable_timeouts(timeouts, 2);
918
919 /* Unlink myself from the wait queue, if on it (might not be anymore!) */
920 partitionLock = LockHashPartitionLock(lockAwaited->hashcode);
921 LWLockAcquire(partitionLock, LW_EXCLUSIVE);
922
923 if (MyProc->links.next != NULL)
924 {
925 /* We could not have been granted the lock yet */
926 RemoveFromWaitQueue(MyProc, lockAwaited->hashcode);
927 }
928 else
929 {
930 /*
931 * Somebody kicked us off the lock queue already. Perhaps they
932 * granted us the lock, or perhaps they detected a deadlock. If they
933 * did grant us the lock, we'd better remember it in our local lock
934 * table.
935 */
936 if (MyProc->waitStatus == PROC_WAIT_STATUS_OK)
937 GrantAwaitedLock();

Callers 4

ProcessInterruptsFunction · 0.85
ProcReleaseLocksFunction · 0.85
AbortTransactionFunction · 0.85
AbortSubTransactionFunction · 0.85

Calls 6

AbortStrongLockAcquireFunction · 0.85
disable_timeoutsFunction · 0.85
LWLockAcquireFunction · 0.85
RemoveFromWaitQueueFunction · 0.85
GrantAwaitedLockFunction · 0.85
LWLockReleaseFunction · 0.85

Tested by

no test coverage detected