Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcafdbc

Browse files
committed
Improve error reporting in code that checks for buffer refcount leaks.
Formerly we just Assert'ed that each refcount was zero, which was quickand easy but failed to provide a good overview of what was wrong.Change the code so that we'll call PrintBufferLeakWarning() for eachbuffer 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
1 parent73e7025 commitdcafdbc

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,12 +1699,18 @@ AtEOXact_Buffers(bool isCommit)
16991699
#ifdefUSE_ASSERT_CHECKING
17001700
if (assert_enabled)
17011701
{
1702-
inti;
1702+
intRefCountErrors=0;
1703+
Bufferb;
17031704

1704-
for (i=0;i<NBuffers;i++)
1705+
for (b=1;b <=NBuffers;b++)
17051706
{
1706-
Assert(PrivateRefCount[i]==0);
1707+
if (PrivateRefCount[b-1]!=0)
1708+
{
1709+
PrintBufferLeakWarning(b);
1710+
RefCountErrors++;
1711+
}
17071712
}
1713+
Assert(RefCountErrors==0);
17081714
}
17091715
#endif
17101716

@@ -1739,12 +1745,18 @@ AtProcExit_Buffers(int code, Datum arg)
17391745
#ifdefUSE_ASSERT_CHECKING
17401746
if (assert_enabled)
17411747
{
1742-
inti;
1748+
intRefCountErrors=0;
1749+
Bufferb;
17431750

1744-
for (i=0;i<NBuffers;i++)
1751+
for (b=1;b <=NBuffers;b++)
17451752
{
1746-
Assert(PrivateRefCount[i]==0);
1753+
if (PrivateRefCount[b-1]!=0)
1754+
{
1755+
PrintBufferLeakWarning(b);
1756+
RefCountErrors++;
1757+
}
17471758
}
1759+
Assert(RefCountErrors==0);
17481760
}
17491761
#endif
17501762

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,22 @@ void
497497
AtEOXact_LocalBuffers(boolisCommit)
498498
{
499499
#ifdefUSE_ASSERT_CHECKING
500-
if (assert_enabled)
500+
if (assert_enabled&&LocalRefCount)
501501
{
502+
intRefCountErrors=0;
502503
inti;
503504

504505
for (i=0;i<NLocBuffer;i++)
505506
{
506-
Assert(LocalRefCount[i]==0);
507+
if (LocalRefCount[i]!=0)
508+
{
509+
Bufferb=-i-1;
510+
511+
PrintBufferLeakWarning(b);
512+
RefCountErrors++;
513+
}
507514
}
515+
Assert(RefCountErrors==0);
508516
}
509517
#endif
510518
}
@@ -523,12 +531,20 @@ AtProcExit_LocalBuffers(void)
523531
#ifdefUSE_ASSERT_CHECKING
524532
if (assert_enabled&&LocalRefCount)
525533
{
534+
intRefCountErrors=0;
526535
inti;
527536

528537
for (i=0;i<NLocBuffer;i++)
529538
{
530-
Assert(LocalRefCount[i]==0);
539+
if (LocalRefCount[i]!=0)
540+
{
541+
Bufferb=-i-1;
542+
543+
PrintBufferLeakWarning(b);
544+
RefCountErrors++;
545+
}
531546
}
547+
Assert(RefCountErrors==0);
532548
}
533549
#endif
534550
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp