]> granicus.if.org Git - postgresql/commitdiff
Ensure that catcache 'busy' flags are reset at transaction abort.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 6 Aug 2000 04:17:47 +0000 (04:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 6 Aug 2000 04:17:47 +0000 (04:17 +0000)
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.

src/backend/access/transam/xact.c
src/backend/utils/cache/catcache.c
src/include/utils/catcache.h

index 74ffb134b41f59a0a008a5e0ccea435abb21f793..812e137071cfb134f42e5b06ac4b86bc017c1407 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.69 2000/07/02 02:28:38 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.70 2000/08/06 04:17:47 tgl Exp $
  *
  * NOTES
  *             Transaction aborts can now occur two ways:
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/portal.h"
+#include "utils/catcache.h"
 #include "utils/relcache.h"
 #include "utils/temprel.h"
 
@@ -797,6 +798,7 @@ static void
 AtAbort_Cache()
 {
        RelationCacheAbort();
+       SystemCacheAbort();
        RegisterInvalid(false);
 }
 
index 037fe69e81d103ba1900b9f805359558f25aa8f1..1c0b39c84b548b65b3c8fea0e5fbb270050ab8fd 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.69 2000/07/02 05:38:40 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.70 2000/08/06 04:17:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -506,6 +506,7 @@ CatalogCacheIdInvalidate(int cacheId,       /* XXX */
  *                                        public functions
  *
  *             ResetSystemCache
+ *             SystemCacheAbort
  *             InitIndexedSysCache
  *             InitSysCache
  *             SearchSysCache
@@ -517,7 +518,7 @@ CatalogCacheIdInvalidate(int cacheId,       /* XXX */
  * --------------------------------
  */
 void
-ResetSystemCache()
+ResetSystemCache(void)
 {
        CatCache *cache;
 
@@ -545,18 +546,43 @@ ResetSystemCache()
                        {
                                nextelt = DLGetSucc(elt);
                                CatCacheRemoveCTup(cache, elt);
-                               if (cache->cc_ntup < 0)
-                                       elog(NOTICE,
-                                                "ResetSystemCache: cc_ntup<0 (software error)");
                        }
                }
-               cache->cc_ntup = 0;             /* in case of WARN error above */
-               cache->busy = false;    /* to recover from recursive-use error */
+
+               /* double-check that ntup is now zero */
+               if (cache->cc_ntup != 0)
+               {
+                       elog(NOTICE,
+                                "ResetSystemCache: cache %d has cc_ntup = %d, should be 0",
+                                cache->id, cache->cc_ntup);
+                       cache->cc_ntup = 0;
+               }
        }
 
        CACHE1_elog(DEBUG, "end of ResetSystemCache call");
 }
 
+/* --------------------------------
+ *             SystemCacheAbort
+ *
+ * This routine is called to clean up catcache state as needed during
+ * transaction abort.
+ * --------------------------------
+ */
+void
+SystemCacheAbort(void)
+{
+       CatCache *cache;
+
+       /* ----------------
+        *      clear the "cache busy" flags, which may have been left set if we
+        *      elog'd out during a cache lookup attempt.
+        * ----------------
+        */
+       for (cache = Caches; PointerIsValid(cache); cache = cache->cc_next)
+               cache->busy = false;
+}
+
 /* --------------------------------
  *             SystemCacheRelationFlushed
  *
index cba400bc005cb92764dac55c51a1050f508294e9..369dfd02c5963c227e8791bbfb19ff1ae192cdb5 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catcache.h,v 1.25 2000/06/28 03:33:33 tgl Exp $
+ * $Id: catcache.h,v 1.26 2000/08/06 04:16:40 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -83,6 +83,7 @@ extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
                                                 ItemPointer pointer);
 extern void ResetSystemCache(void);
 extern void SystemCacheRelationFlushed(Oid relId);
+extern void SystemCacheAbort(void);
 extern CatCache *InitSysCache(char *relname, char *indname, int id,
                                                          int nkeys, int *key,
                                                          ScanFunc iScanfuncP);