Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a64b5a9

Browse files
committed
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 fdf89f7 commit a64b5a9

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
@@ -2120,9 +2120,6 @@ CommitTransaction(void)
21202120
*/
21212121
smgrDoPendingDeletes(true);
21222122

2123-
/* Check we've released all catcache entries */
2124-
AtEOXact_CatCache(true);
2125-
21262123
AtCommit_Notify();
21272124
AtEOXact_GUC(true, 1);
21282125
AtEOXact_SPI(true);
@@ -2391,9 +2388,6 @@ PrepareTransaction(void)
23912388
*/
23922389
PostPrepare_Twophase();
23932390

2394-
/* Check we've released all catcache entries */
2395-
AtEOXact_CatCache(true);
2396-
23972391
/* PREPARE acts the same as COMMIT as far as GUC is concerned */
23982392
AtEOXact_GUC(true, 1);
23992393
AtEOXact_SPI(true);
@@ -2593,7 +2587,6 @@ AbortTransaction(void)
25932587
RESOURCE_RELEASE_AFTER_LOCKS,
25942588
false, true);
25952589
smgrDoPendingDeletes(false);
2596-
AtEOXact_CatCache(false);
25972590

25982591
AtEOXact_GUC(false, 1);
25992592
AtEOXact_SPI(false);

src/backend/utils/cache/catcache.c

-51
Original file line numberDiff line numberDiff line change
@@ -526,57 +526,6 @@ CreateCacheMemoryContext(void)
526526
}
527527

528528

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

src/include/utils/catcache.h

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ typedef struct catcacheheader
162162
extern PGDLLIMPORT MemoryContext CacheMemoryContext;
163163

164164
extern void CreateCacheMemoryContext(void);
165-
extern void AtEOXact_CatCache(bool isCommit);
166165

167166
extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
168167
int nkeys, const int *key,

0 commit comments

Comments
 (0)