* 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.) */
| 878 | * wait is within the realm of possibility, too.) |
| 879 | */ |
| 880 | void |
| 881 | LockErrorCleanup(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(); |
no test coverage detected