Warn if LOCKTAG_TUPLE is held at commit, under debug_assertions.
authorNoah Misch <[email protected]>
Tue, 24 Sep 2024 22:25:18 +0000 (15:25 -0700)
committerNoah Misch <[email protected]>
Tue, 24 Sep 2024 22:25:25 +0000 (15:25 -0700)
The current use always releases this locktag.  A planned use will
continue that intent.  It will involve more areas of code, making unlock
omissions easier.  Warn under debug_assertions, like we do for various
resource leaks.  Back-patch to v12 (all supported versions), the plan
for the commit of the new use.

Reviewed by Heikki Linnakangas.

Discussion: https://postgr.es/m/20240512232923[email protected]

src/backend/storage/lmgr/lock.c
src/include/storage/lock.h

index 5e36d91d6150ad77e4ccae90348752064b319f87..17bc7257732579de274daa24a6be8487adb1c8f6 100644 (file)
@@ -2211,6 +2211,16 @@ LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
                locallock->numLockOwners = 0;
        }
 
+#ifdef USE_ASSERT_CHECKING
+
+       /*
+        * Tuple locks are currently held only for short durations within a
+        * transaction. Check that we didn't forget to release one.
+        */
+       if (LOCALLOCK_LOCKTAG(*locallock) == LOCKTAG_TUPLE && !allLocks)
+           elog(WARNING, "tuple lock held at commit");
+#endif
+
        /*
         * If the lock or proclock pointers are NULL, this lock was taken via
         * the relation fast-path (and is not known to have been transferred).
index 304e2a5c949bcec4fd31a4cc8db122c2583502b9..7066b0510b09ba88dd861d23d2e1f05a1dce1b2b 100644 (file)
@@ -432,6 +432,7 @@ typedef struct LOCALLOCK
 } LOCALLOCK;
 
 #define LOCALLOCK_LOCKMETHOD(llock) ((llock).tag.lock.locktag_lockmethodid)
+#define LOCALLOCK_LOCKTAG(llock) ((LockTagType) (llock).tag.lock.locktag_type)
 
 
 /*