Commit c2281ac8 authored by Robert Haas's avatar Robert Haas

Remove belt-and-suspenders guards against buffer pin leaks.

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.
parent 58dfb07b
...@@ -1659,31 +1659,26 @@ InitBufferPoolBackend(void) ...@@ -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 static void
AtProcExit_Buffers(int code, Datum arg) AtProcExit_Buffers(int code, Datum arg)
{ {
int i;
AbortBufferIO(); AbortBufferIO();
UnlockBuffers(); UnlockBuffers();
for (i = 0; i < NBuffers; i++) #ifdef USE_ASSERT_CHECKING
if (assert_enabled)
{ {
if (PrivateRefCount[i] != 0) int i;
{
volatile BufferDesc *buf = &(BufferDescriptors[i]);
/* for (i = 0; i < NBuffers; 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);
Assert(PrivateRefCount[i] == 0); Assert(PrivateRefCount[i] == 0);
} }
} }
#endif
/* localbuf.c needs a chance too */ /* localbuf.c needs a chance too */
AtProcExit_LocalBuffers(); AtProcExit_LocalBuffers();
......
...@@ -468,14 +468,23 @@ AtEOXact_LocalBuffers(bool isCommit) ...@@ -468,14 +468,23 @@ AtEOXact_LocalBuffers(bool isCommit)
/* /*
* AtProcExit_LocalBuffers - ensure we have dropped pins during backend exit. * AtProcExit_LocalBuffers - ensure we have dropped pins during backend exit.
* *
* This is just like AtProcExit_Buffers, but for local buffers. We have * This is just like AtProcExit_Buffers, but for local buffers. We shouldn't
* to drop pins to ensure that any attempt to drop temp files doesn't * be holding any remaining pins; if we are, and assertions aren't enabled,
* fail in DropRelFileNodeBuffers. * we'll fail later in DropRelFileNodeBuffers while trying to drop the temp
* rels.
*/ */
void void
AtProcExit_LocalBuffers(void) AtProcExit_LocalBuffers(void)
{ {
/* just zero the refcounts ... */ #ifdef USE_ASSERT_CHECKING
if (LocalRefCount) if (assert_enabled && LocalRefCount)
MemSet(LocalRefCount, 0, NLocBuffer * sizeof(*LocalRefCount)); {
int i;
for (i = 0; i < NLocBuffer; i++)
{
Assert(LocalRefCount[i] == 0);
}
}
#endif
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment