Skip to content

Commit 925418d

Browse files
committed
Ensure that catcache 'busy' flags are reset at transaction abort.
Without this, an elog during cache-entry load leaves that catcache unusable. elog in that segment of code is pretty unusual but it can happen.
1 parent 465a3b0 commit 925418d

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

src/backend/access/transam/xact.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.69 2000/07/02 02:28:38 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.70 2000/08/06 04:17:47 tgl Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -167,6 +167,7 @@
167167
#include "utils/inval.h"
168168
#include "utils/memutils.h"
169169
#include "utils/portal.h"
170+
#include "utils/catcache.h"
170171
#include "utils/relcache.h"
171172
#include "utils/temprel.h"
172173

@@ -797,6 +798,7 @@ static void
797798
AtAbort_Cache()
798799
{
799800
RelationCacheAbort();
801+
SystemCacheAbort();
800802
RegisterInvalid(false);
801803
}
802804

src/backend/utils/cache/catcache.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.69 2000/07/02 05:38:40 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.70 2000/08/06 04:17:16 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -506,6 +506,7 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
506506
* public functions
507507
*
508508
* ResetSystemCache
509+
* SystemCacheAbort
509510
* InitIndexedSysCache
510511
* InitSysCache
511512
* SearchSysCache
@@ -517,7 +518,7 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
517518
* --------------------------------
518519
*/
519520
void
520-
ResetSystemCache()
521+
ResetSystemCache(void)
521522
{
522523
CatCache *cache;
523524

@@ -545,18 +546,43 @@ ResetSystemCache()
545546
{
546547
nextelt = DLGetSucc(elt);
547548
CatCacheRemoveCTup(cache, elt);
548-
if (cache->cc_ntup < 0)
549-
elog(NOTICE,
550-
"ResetSystemCache: cc_ntup<0 (software error)");
551549
}
552550
}
553-
cache->cc_ntup = 0; /* in case of WARN error above */
554-
cache->busy = false; /* to recover from recursive-use error */
551+
552+
/* double-check that ntup is now zero */
553+
if (cache->cc_ntup != 0)
554+
{
555+
elog(NOTICE,
556+
"ResetSystemCache: cache %d has cc_ntup = %d, should be 0",
557+
cache->id, cache->cc_ntup);
558+
cache->cc_ntup = 0;
559+
}
555560
}
556561

557562
CACHE1_elog(DEBUG, "end of ResetSystemCache call");
558563
}
559564

565+
/* --------------------------------
566+
* SystemCacheAbort
567+
*
568+
* This routine is called to clean up catcache state as needed during
569+
* transaction abort.
570+
* --------------------------------
571+
*/
572+
void
573+
SystemCacheAbort(void)
574+
{
575+
CatCache *cache;
576+
577+
/* ----------------
578+
* clear the "cache busy" flags, which may have been left set if we
579+
* elog'd out during a cache lookup attempt.
580+
* ----------------
581+
*/
582+
for (cache = Caches; PointerIsValid(cache); cache = cache->cc_next)
583+
cache->busy = false;
584+
}
585+
560586
/* --------------------------------
561587
* SystemCacheRelationFlushed
562588
*

src/include/utils/catcache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: catcache.h,v 1.25 2000/06/28 03:33:33 tgl Exp $
10+
* $Id: catcache.h,v 1.26 2000/08/06 04:16:40 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -83,6 +83,7 @@ extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
8383
ItemPointer pointer);
8484
extern void ResetSystemCache(void);
8585
extern void SystemCacheRelationFlushed(Oid relId);
86+
extern void SystemCacheAbort(void);
8687
extern CatCache *InitSysCache(char *relname, char *indname, int id,
8788
int nkeys, int *key,
8889
ScanFunc iScanfuncP);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy