mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-07 19:47:50 +08:00
Improve error reporting in code that checks for buffer refcount leaks.
Formerly we just Assert'ed that each refcount was zero, which was quick and easy but failed to provide a good overview of what was wrong. Change the code so that we'll call PrintBufferLeakWarning() for each buffer with a nonzero refcount, and then Assert at the end of the loop. This costs nothing in runtime and might ease diagnosis of some bugs. Greg Smith, reviewed by Satoshi Nagayasu, further tweaked by me
This commit is contained in:
parent
73e7025bd8
commit
dcafdbcde1
@ -1699,12 +1699,18 @@ AtEOXact_Buffers(bool isCommit)
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
if (assert_enabled)
|
||||
{
|
||||
int i;
|
||||
int RefCountErrors = 0;
|
||||
Buffer b;
|
||||
|
||||
for (i = 0; i < NBuffers; i++)
|
||||
for (b = 1; b <= NBuffers; b++)
|
||||
{
|
||||
Assert(PrivateRefCount[i] == 0);
|
||||
if (PrivateRefCount[b - 1] != 0)
|
||||
{
|
||||
PrintBufferLeakWarning(b);
|
||||
RefCountErrors++;
|
||||
}
|
||||
}
|
||||
Assert(RefCountErrors == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1739,12 +1745,18 @@ AtProcExit_Buffers(int code, Datum arg)
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
if (assert_enabled)
|
||||
{
|
||||
int i;
|
||||
int RefCountErrors = 0;
|
||||
Buffer b;
|
||||
|
||||
for (i = 0; i < NBuffers; i++)
|
||||
for (b = 1; b <= NBuffers; b++)
|
||||
{
|
||||
Assert(PrivateRefCount[i] == 0);
|
||||
if (PrivateRefCount[b - 1] != 0)
|
||||
{
|
||||
PrintBufferLeakWarning(b);
|
||||
RefCountErrors++;
|
||||
}
|
||||
}
|
||||
Assert(RefCountErrors == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -497,14 +497,22 @@ void
|
||||
AtEOXact_LocalBuffers(bool isCommit)
|
||||
{
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
if (assert_enabled)
|
||||
if (assert_enabled && LocalRefCount)
|
||||
{
|
||||
int RefCountErrors = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
Assert(LocalRefCount[i] == 0);
|
||||
if (LocalRefCount[i] != 0)
|
||||
{
|
||||
Buffer b = -i - 1;
|
||||
|
||||
PrintBufferLeakWarning(b);
|
||||
RefCountErrors++;
|
||||
}
|
||||
}
|
||||
Assert(RefCountErrors == 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -523,12 +531,20 @@ AtProcExit_LocalBuffers(void)
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
if (assert_enabled && LocalRefCount)
|
||||
{
|
||||
int RefCountErrors = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
Assert(LocalRefCount[i] == 0);
|
||||
if (LocalRefCount[i] != 0)
|
||||
{
|
||||
Buffer b = -i - 1;
|
||||
|
||||
PrintBufferLeakWarning(b);
|
||||
RefCountErrors++;
|
||||
}
|
||||
}
|
||||
Assert(RefCountErrors == 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user