Remove belt-and-suspenders guards against buffer pin leaks.
authorRobert Haas <[email protected]>
Thu, 25 Nov 2010 05:06:46 +0000 (00:06 -0500)
committerRobert Haas <[email protected]>
Thu, 25 Nov 2010 05:06:46 +0000 (00:06 -0500)
Forcibly releasing all leftover buffer pins should be unnecessary now
that we have a robust ResourceOwner mechanism, and it significantly
increases the cost of process shutdown.  Instead, in an assert-enabled
build, assert that no pins are held; in a non-assert-enabled build, do
nothing.

src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/localbuf.c

index 54c7109983dcda3e94fe734638757eece1a22e3d..edc497788dfaa0b3d354b20682114406c64d34f3 100644 (file)
@@ -1659,31 +1659,26 @@ InitBufferPoolBackend(void)
 }
 
 /*
- * Ensure we have released all shared-buffer locks and pins during backend exit
+ * During backend exit, ensure that we released all shared-buffer locks and
+ * assert that we have no remaining pins.
  */
 static void
 AtProcExit_Buffers(int code, Datum arg)
 {
-   int         i;
-
    AbortBufferIO();
    UnlockBuffers();
 
-   for (i = 0; i < NBuffers; i++)
+#ifdef USE_ASSERT_CHECKING
+   if (assert_enabled)
    {
-       if (PrivateRefCount[i] != 0)
-       {
-           volatile BufferDesc *buf = &(BufferDescriptors[i]);
+       int         i;
 
-           /*
-            * We don't worry about updating ResourceOwner; if we even got
-            * here, it suggests that ResourceOwners are messed up.
-            */
-           PrivateRefCount[i] = 1;     /* make sure we release shared pin */
-           UnpinBuffer(buf, false);
+       for (i = 0; i < NBuffers; i++)
+       {
            Assert(PrivateRefCount[i] == 0);
        }
    }
+#endif
 
    /* localbuf.c needs a chance too */
    AtProcExit_LocalBuffers();
index 46fddde187b7496415b478c42b88e9997daadef2..059c7f18477b72f4b2e0ffdf35a259fdccf318b7 100644 (file)
@@ -468,14 +468,23 @@ AtEOXact_LocalBuffers(bool isCommit)
 /*
  * AtProcExit_LocalBuffers - ensure we have dropped pins during backend exit.
  *
- * This is just like AtProcExit_Buffers, but for local buffers.  We have
- * to drop pins to ensure that any attempt to drop temp files doesn't
- * fail in DropRelFileNodeBuffers.
+ * This is just like AtProcExit_Buffers, but for local buffers.  We shouldn't
+ * be holding any remaining pins; if we are, and assertions aren't enabled,
+ * we'll fail later in DropRelFileNodeBuffers while trying to drop the temp
+ * rels.
  */
 void
 AtProcExit_LocalBuffers(void)
 {
-   /* just zero the refcounts ... */
-   if (LocalRefCount)
-       MemSet(LocalRefCount, 0, NLocBuffer * sizeof(*LocalRefCount));
+#ifdef USE_ASSERT_CHECKING
+   if (assert_enabled && LocalRefCount)
+   {
+       int         i;
+
+       for (i = 0; i < NLocBuffer; i++)
+       {
+           Assert(LocalRefCount[i] == 0);
+       }
+   }
+#endif
 }