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

Commit3bdcf6a

Browse files
committed
Don't allow to disable backend assertions via the debug_assertions GUC.
The existance of the assert_enabled variable (backing thedebug_assertions GUC) reduced the amount of knowledge some static codecheckers (like coverity and various compilers) could infer from theexistance of the assertion. That could have been solved by optionallyremoving the assertion_enabled variable from the Assert() et al macrosat compile time when some special macro is defined, but the resultingcomplication doesn't seem to be worth the gain from havingdebug_assertions. Recompiling is fast enough.The debug_assertions GUC is still available, but readonly, as it'suseful when diagnosing problems. The commandline/client startup option-A, which previously also allowed to enable/disable assertions, hasbeen removed as it doesn't serve a purpose anymore.While at it, reduce code duplication in bufmgr.c and localbuf.cassertions checking for spurious buffer pins. That code had to bereindented anyway to cope with the assert_enabled removal.
1 parent45b0f35 commit3bdcf6a

File tree

14 files changed

+106
-177
lines changed

14 files changed

+106
-177
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6722,6 +6722,26 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
67226722
</listitem>
67236723
</varlistentry>
67246724

6725+
<varlistentry id="guc-debug-assertions" xreflabel="debug_assertions">
6726+
<term><varname>debug_assertions</varname> (<type>boolean</type>)
6727+
<indexterm>
6728+
<primary><varname>debug_assertions</> configuration parameter</primary>
6729+
</indexterm>
6730+
</term>
6731+
<listitem>
6732+
<para>
6733+
Reports whether <productname>PostgreSQL</productname> has been built
6734+
with assertions enabled. That is the case if the
6735+
macro <symbol>USE_ASSERT_CHECKING</symbol> is defined
6736+
when <productname>PostgreSQL</productname> is built (accomplished
6737+
e.g. by the <command>configure</command> option
6738+
<option>--enable-cassert</option>). By
6739+
default <productname>PostgreSQL</productname> is built without
6740+
assertions.
6741+
</para>
6742+
</listitem>
6743+
</varlistentry>
6744+
67256745
<varlistentry id="guc-integer-datetimes" xreflabel="integer_datetimes">
67266746
<term><varname>integer_datetimes</varname> (<type>boolean</type>)
67276747
<indexterm>
@@ -6973,28 +6993,6 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
69736993
</listitem>
69746994
</varlistentry>
69756995

6976-
<varlistentry id="guc-debug-assertions" xreflabel="debug_assertions">
6977-
<term><varname>debug_assertions</varname> (<type>boolean</type>)
6978-
<indexterm>
6979-
<primary><varname>debug_assertions</> configuration parameter</primary>
6980-
</indexterm>
6981-
</term>
6982-
<listitem>
6983-
<para>
6984-
Turns on various assertion checks. This is a debugging aid. If
6985-
you are experiencing strange problems or crashes you might want
6986-
to turn this on, as it might expose programming mistakes. To use
6987-
this parameter, the macro <symbol>USE_ASSERT_CHECKING</symbol>
6988-
must be defined when <productname>PostgreSQL</productname> is
6989-
built (accomplished by the <command>configure</command> option
6990-
<option>--enable-cassert</option>). Note that
6991-
<varname>debug_assertions</varname> defaults to <literal>on</>
6992-
if <productname>PostgreSQL</productname> has been built with
6993-
assertions enabled.
6994-
</para>
6995-
</listitem>
6996-
</varlistentry>
6997-
69986996
<varlistentry id="guc-ignore-system-indexes" xreflabel="ignore_system_indexes">
69996997
<term><varname>ignore_system_indexes</varname> (<type>boolean</type>)
70006998
<indexterm>
@@ -7354,10 +7352,6 @@ LOG: CleanUpLock: deleting: lock(0xb7acd844) id(24688,24696,0,0,0,1)
73547352
</thead>
73557353

73567354
<tbody>
7357-
<row>
7358-
<entry><option>-A <replaceable>x</replaceable></option></entry>
7359-
<entry><literal>debug_assertions = <replaceable>x</replaceable></></entry>
7360-
</row>
73617355
<row>
73627356
<entry><option>-B <replaceable>x</replaceable></option></entry>
73637357
<entry><literal>shared_buffers = <replaceable>x</replaceable></></entry>

‎doc/src/sgml/ref/postgres-ref.sgml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,6 @@ PostgreSQL documentation
101101
<title>General Purpose</title>
102102

103103
<variablelist>
104-
<varlistentry>
105-
<term><option>-A 0|1</option></term>
106-
<listitem>
107-
<para>
108-
Enables run-time assertion checks, which is a debugging aid to
109-
detect programming mistakes. This option is only available if
110-
assertions were enabled when <productname>PostgreSQL</> was
111-
compiled. If so, the default is on.
112-
</para>
113-
</listitem>
114-
</varlistentry>
115-
116104
<varlistentry>
117105
<term><option>-B <replaceable class="parameter">nbuffers</replaceable></option></term>
118106
<listitem>

‎src/backend/access/gin/ginpostinglist.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize,
250250
* Check that the encoded segment decodes back to the original items.
251251
*/
252252
#if defined (CHECK_ENCODING_ROUNDTRIP)
253-
if (assert_enabled)
254253
{
255254
intndecoded;
256255
ItemPointertmp=ginPostingListDecode(result,&ndecoded);

‎src/backend/commands/event_trigger.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ EventTriggerCommonSetup(Node *parsetree,
635635
* relevant command tag.
636636
*/
637637
#ifdefUSE_ASSERT_CHECKING
638-
if (assert_enabled)
639638
{
640639
constchar*dbgtag;
641640

‎src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,10 @@ PostmasterMain(int argc, char *argv[])
603603
* tcop/postgres.c (the option sets should not conflict) and with the
604604
* common help() function in main/main.c.
605605
*/
606-
while ((opt=getopt(argc,argv,"A:B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:"))!=-1)
606+
while ((opt=getopt(argc,argv,"B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:"))!=-1)
607607
{
608608
switch (opt)
609609
{
610-
case'A':
611-
SetConfigOption("debug_assertions",optarg,PGC_POSTMASTER,PGC_S_ARGV);
612-
break;
613-
614610
case'B':
615611
SetConfigOption("shared_buffers",optarg,PGC_POSTMASTER,PGC_S_ARGV);
616612
break;

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

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static volatile BufferDesc *BufferAlloc(SMgrRelation smgr,
109109
bool*foundPtr);
110110
staticvoidFlushBuffer(volatileBufferDesc*buf,SMgrRelationreln);
111111
staticvoidAtProcExit_Buffers(intcode,Datumarg);
112+
staticvoidCheckForBufferLeaks(void);
112113
staticintrnode_comparator(constvoid*p1,constvoid*p2);
113114

114115

@@ -1699,34 +1700,13 @@ SyncOneBuffer(int buf_id, bool skip_recently_used)
16991700
returnresult |BUF_WRITTEN;
17001701
}
17011702

1702-
17031703
/*
17041704
*AtEOXact_Buffers - clean up at end of transaction.
1705-
*
1706-
*As of PostgreSQL 8.0, buffer pins should get released by the
1707-
*ResourceOwner mechanism. This routine is just a debugging
1708-
*cross-check that no pins remain.
17091705
*/
17101706
void
17111707
AtEOXact_Buffers(boolisCommit)
17121708
{
1713-
#ifdefUSE_ASSERT_CHECKING
1714-
if (assert_enabled)
1715-
{
1716-
intRefCountErrors=0;
1717-
Bufferb;
1718-
1719-
for (b=1;b <=NBuffers;b++)
1720-
{
1721-
if (PrivateRefCount[b-1]!=0)
1722-
{
1723-
PrintBufferLeakWarning(b);
1724-
RefCountErrors++;
1725-
}
1726-
}
1727-
Assert(RefCountErrors==0);
1728-
}
1729-
#endif
1709+
CheckForBufferLeaks();
17301710

17311711
AtEOXact_LocalBuffers(isCommit);
17321712
}
@@ -1756,26 +1736,36 @@ AtProcExit_Buffers(int code, Datum arg)
17561736
AbortBufferIO();
17571737
UnlockBuffers();
17581738

1739+
CheckForBufferLeaks();
1740+
1741+
/* localbuf.c needs a chance too */
1742+
AtProcExit_LocalBuffers();
1743+
}
1744+
1745+
/*
1746+
*CheckForBufferLeaks - ensure this backend holds no buffer pins
1747+
*
1748+
*As of PostgreSQL 8.0, buffer pins should get released by the
1749+
*ResourceOwner mechanism. This routine is just a debugging
1750+
*cross-check that no pins remain.
1751+
*/
1752+
staticvoid
1753+
CheckForBufferLeaks(void)
1754+
{
17591755
#ifdefUSE_ASSERT_CHECKING
1760-
if (assert_enabled)
1761-
{
1762-
intRefCountErrors=0;
1763-
Bufferb;
1756+
intRefCountErrors=0;
1757+
Bufferb;
17641758

1765-
for (b=1;b <=NBuffers;b++)
1759+
for (b=1;b <=NBuffers;b++)
1760+
{
1761+
if (PrivateRefCount[b-1]!=0)
17661762
{
1767-
if (PrivateRefCount[b-1]!=0)
1768-
{
1769-
PrintBufferLeakWarning(b);
1770-
RefCountErrors++;
1771-
}
1763+
PrintBufferLeakWarning(b);
1764+
RefCountErrors++;
17721765
}
1773-
Assert(RefCountErrors==0);
17741766
}
1767+
Assert(RefCountErrors==0);
17751768
#endif
1776-
1777-
/* localbuf.c needs a chance too */
1778-
AtProcExit_LocalBuffers();
17791769
}
17801770

17811771
/*

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

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,15 @@ GetLocalBufferStorage(void)
491491
}
492492

493493
/*
494-
*AtEOXact_LocalBuffers -clean up at end of transaction.
494+
*CheckForLocalBufferLeaks -ensure this backend holds no local buffer pins
495495
*
496-
* This is just likeAtEOXact_Buffers, but for local buffers.
496+
* This is just likeCheckBufferLeaks(), but for local buffers.
497497
*/
498-
void
499-
AtEOXact_LocalBuffers(boolisCommit)
498+
staticvoid
499+
CheckForLocalBufferLeaks(void)
500500
{
501501
#ifdefUSE_ASSERT_CHECKING
502-
if (assert_enabled&&LocalRefCount)
502+
if (LocalRefCount)
503503
{
504504
intRefCountErrors=0;
505505
inti;
@@ -519,34 +519,29 @@ AtEOXact_LocalBuffers(bool isCommit)
519519
#endif
520520
}
521521

522+
/*
523+
* AtEOXact_LocalBuffers - clean up at end of transaction.
524+
*
525+
* This is just like AtEOXact_Buffers, but for local buffers.
526+
*/
527+
void
528+
AtEOXact_LocalBuffers(boolisCommit)
529+
{
530+
CheckForLocalBufferLeaks();
531+
}
532+
522533
/*
523534
* AtProcExit_LocalBuffers - ensure we have dropped pins during backend exit.
524535
*
525-
* This is just like AtProcExit_Buffers, but for local buffers. We shouldn't
526-
* be holding any remaining pins; if we are, and assertions aren't enabled,
527-
* we'll fail later in DropRelFileNodeBuffers while trying to drop the temp
528-
* rels.
536+
* This is just like AtProcExit_Buffers, but for local buffers.
529537
*/
530538
void
531539
AtProcExit_LocalBuffers(void)
532540
{
533-
#ifdefUSE_ASSERT_CHECKING
534-
if (assert_enabled&&LocalRefCount)
535-
{
536-
intRefCountErrors=0;
537-
inti;
538-
539-
for (i=0;i<NLocBuffer;i++)
540-
{
541-
if (LocalRefCount[i]!=0)
542-
{
543-
Bufferb=-i-1;
544-
545-
PrintBufferLeakWarning(b);
546-
RefCountErrors++;
547-
}
548-
}
549-
Assert(RefCountErrors==0);
550-
}
551-
#endif
541+
/*
542+
* We shouldn't be holding any remaining pins; if we are, and assertions
543+
* aren't enabled, we'll fail later in DropRelFileNodeBuffers while trying
544+
* to drop the temp rels.
545+
*/
546+
CheckForLocalBufferLeaks();
552547
}

‎src/backend/storage/lmgr/proc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ InitProcess(void)
376376
MyProc->waitLock=NULL;
377377
MyProc->waitProcLock=NULL;
378378
#ifdefUSE_ASSERT_CHECKING
379-
if (assert_enabled)
380379
{
381380
inti;
382381

@@ -539,7 +538,6 @@ InitAuxiliaryProcess(void)
539538
MyProc->waitLock=NULL;
540539
MyProc->waitProcLock=NULL;
541540
#ifdefUSE_ASSERT_CHECKING
542-
if (assert_enabled)
543541
{
544542
inti;
545543

@@ -782,7 +780,6 @@ ProcKill(int code, Datum arg)
782780
SyncRepCleanupAtProcExit();
783781

784782
#ifdefUSE_ASSERT_CHECKING
785-
if (assert_enabled)
786783
{
787784
inti;
788785

‎src/backend/tcop/postgres.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,14 +3305,10 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx,
33053305
* postmaster/postmaster.c (the option sets should not conflict) and with
33063306
* the common help() function in main/main.c.
33073307
*/
3308-
while ((flag=getopt(argc,argv,"A:B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:"))!=-1)
3308+
while ((flag=getopt(argc,argv,"B:bc:C:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:"))!=-1)
33093309
{
33103310
switch (flag)
33113311
{
3312-
case'A':
3313-
SetConfigOption("debug_assertions",optarg,ctx,gucsource);
3314-
break;
3315-
33163312
case'B':
33173313
SetConfigOption("shared_buffers",optarg,ctx,gucsource);
33183314
break;

‎src/backend/utils/cache/catcache.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -553,41 +553,38 @@ void
553553
AtEOXact_CatCache(boolisCommit)
554554
{
555555
#ifdefUSE_ASSERT_CHECKING
556-
if (assert_enabled)
556+
slist_itercache_iter;
557+
558+
slist_foreach(cache_iter,&CacheHdr->ch_caches)
557559
{
558-
slist_itercache_iter;
560+
CatCache*ccp=slist_container(CatCache,cc_next,cache_iter.cur);
561+
dlist_iteriter;
562+
inti;
559563

560-
slist_foreach(cache_iter,&CacheHdr->ch_caches)
564+
/* Check CatCLists */
565+
dlist_foreach(iter,&ccp->cc_lists)
561566
{
562-
CatCache*ccp=slist_container(CatCache,cc_next,cache_iter.cur);
563-
dlist_iteriter;
564-
inti;
567+
CatCList*cl;
565568

566-
/* Check CatCLists */
567-
dlist_foreach(iter,&ccp->cc_lists)
568-
{
569-
CatCList*cl;
569+
cl=dlist_container(CatCList,cache_elem,iter.cur);
570+
Assert(cl->cl_magic==CL_MAGIC);
571+
Assert(cl->refcount==0);
572+
Assert(!cl->dead);
573+
}
570574

571-
cl=dlist_container(CatCList,cache_elem,iter.cur);
572-
Assert(cl->cl_magic==CL_MAGIC);
573-
Assert(cl->refcount==0);
574-
Assert(!cl->dead);
575-
}
575+
/* Check individual tuples */
576+
for (i=0;i<ccp->cc_nbuckets;i++)
577+
{
578+
dlist_head*bucket=&ccp->cc_bucket[i];
576579

577-
/* Check individual tuples */
578-
for (i=0;i<ccp->cc_nbuckets;i++)
580+
dlist_foreach(iter,bucket)
579581
{
580-
dlist_head*bucket=&ccp->cc_bucket[i];
581-
582-
dlist_foreach(iter,bucket)
583-
{
584-
CatCTup*ct;
582+
CatCTup*ct;
585583

586-
ct=dlist_container(CatCTup,cache_elem,iter.cur);
587-
Assert(ct->ct_magic==CT_MAGIC);
588-
Assert(ct->refcount==0);
589-
Assert(!ct->dead);
590-
}
584+
ct=dlist_container(CatCTup,cache_elem,iter.cur);
585+
Assert(ct->ct_magic==CT_MAGIC);
586+
Assert(ct->refcount==0);
587+
Assert(!ct->dead);
591588
}
592589
}
593590
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp