Skip to content

Commit 004a970

Browse files
committedAug 13, 2017
Remove AtEOXact_CatCache().
The sole useful effect of this function, to check that no catcache entries have positive refcounts at transaction end, has really been obsolete since we introduced ResourceOwners in PG 8.1. We reduced the checks to assertions years ago, so that the function was a complete no-op in production builds. There have been previous discussions about removing it entirely, but consensus up to now was that it had some small value as a cross-check for bugs in the ResourceOwner logic. However, it now emerges that it's possible to trigger these assertions if you hit an assert-enabled backend with SIGTERM during a call to SearchCatCacheList, because that function temporarily increases the refcounts of entries it's intending to add to a catcache list construct. In a normal ERROR scenario, the extra refcounts are cleaned up by SearchCatCacheList's PG_CATCH block; but in a FATAL exit we do a transaction abort and exit without ever executing PG_CATCH handlers. There's a case to be made that this is a generic hazard and we should consider restructuring elog(FATAL) handling so that pending PG_CATCH handlers do get run. That's pretty scary though: it could easily create more problems than it solves. Preliminary stress testing by Andreas Seltenreich suggests that there are not many live problems of this ilk, so we rejected that idea. There are more-localized ways to fix the problem; the most principled one would be to use PG_ENSURE_ERROR_CLEANUP instead of plain PG_TRY. But adding cycles to SearchCatCacheList isn't very appealing. We could also weaken the assertions in AtEOXact_CatCache in some more or less ad-hoc way, but that just makes its raison d'etre even less compelling. In the end, the most reasonable solution seems to be to just remove AtEOXact_CatCache altogether, on the grounds that it's not worth trying to fix it. It hasn't found any bugs for us in many years. Per report from Jeevan Chalke. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAM2+6=VEE30YtRQCZX7_sCFsEpoUkFBV1gZazL70fqLn8rcvBA@mail.gmail.com
1 parent 2336f84 commit 004a970

File tree

3 files changed

+0
-59
lines changed

3 files changed

+0
-59
lines changed
 

‎src/backend/access/transam/xact.c

-7
Original file line numberDiff line numberDiff line change
@@ -2124,9 +2124,6 @@ CommitTransaction(void)
21242124
*/
21252125
smgrDoPendingDeletes(true);
21262126

2127-
/* Check we've released all catcache entries */
2128-
AtEOXact_CatCache(true);
2129-
21302127
AtCommit_Notify();
21312128
AtEOXact_GUC(true, 1);
21322129
AtEOXact_SPI(true);
@@ -2405,9 +2402,6 @@ PrepareTransaction(void)
24052402
*/
24062403
PostPrepare_Twophase();
24072404

2408-
/* Check we've released all catcache entries */
2409-
AtEOXact_CatCache(true);
2410-
24112405
/* PREPARE acts the same as COMMIT as far as GUC is concerned */
24122406
AtEOXact_GUC(true, 1);
24132407
AtEOXact_SPI(true);
@@ -2610,7 +2604,6 @@ AbortTransaction(void)
26102604
RESOURCE_RELEASE_AFTER_LOCKS,
26112605
false, true);
26122606
smgrDoPendingDeletes(false);
2613-
AtEOXact_CatCache(false);
26142607

26152608
AtEOXact_GUC(false, 1);
26162609
AtEOXact_SPI(false);

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

-51
Original file line numberDiff line numberDiff line change
@@ -521,57 +521,6 @@ CreateCacheMemoryContext(void)
521521
}
522522

523523

524-
/*
525-
* AtEOXact_CatCache
526-
*
527-
* Clean up catcaches at end of main transaction (either commit or abort)
528-
*
529-
* As of PostgreSQL 8.1, catcache pins should get released by the
530-
* ResourceOwner mechanism. This routine is just a debugging
531-
* cross-check that no pins remain.
532-
*/
533-
void
534-
AtEOXact_CatCache(bool isCommit)
535-
{
536-
#ifdef USE_ASSERT_CHECKING
537-
slist_iter cache_iter;
538-
539-
slist_foreach(cache_iter, &CacheHdr->ch_caches)
540-
{
541-
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
542-
dlist_iter iter;
543-
int i;
544-
545-
/* Check CatCLists */
546-
dlist_foreach(iter, &ccp->cc_lists)
547-
{
548-
CatCList *cl;
549-
550-
cl = dlist_container(CatCList, cache_elem, iter.cur);
551-
Assert(cl->cl_magic == CL_MAGIC);
552-
Assert(cl->refcount == 0);
553-
Assert(!cl->dead);
554-
}
555-
556-
/* Check individual tuples */
557-
for (i = 0; i < ccp->cc_nbuckets; i++)
558-
{
559-
dlist_head *bucket = &ccp->cc_bucket[i];
560-
561-
dlist_foreach(iter, bucket)
562-
{
563-
CatCTup *ct;
564-
565-
ct = dlist_container(CatCTup, cache_elem, iter.cur);
566-
Assert(ct->ct_magic == CT_MAGIC);
567-
Assert(ct->refcount == 0);
568-
Assert(!ct->dead);
569-
}
570-
}
571-
}
572-
#endif
573-
}
574-
575524
/*
576525
* ResetCatalogCache
577526
*

‎src/include/utils/catcache.h

-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ typedef struct catcacheheader
167167
extern PGDLLIMPORT MemoryContext CacheMemoryContext;
168168

169169
extern void CreateCacheMemoryContext(void);
170-
extern void AtEOXact_CatCache(bool isCommit);
171170

172171
extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
173172
int nkeys, const int *key,

0 commit comments

Comments
 (0)
Please sign in to comment.