From: Jan Wieck <jwieck@debis.com>
authorMarc G. Fournier <scrappy@hub.org>
Mon, 23 Feb 1998 17:44:24 +0000 (17:44 +0000)
committerMarc G. Fournier <scrappy@hub.org>
Mon, 23 Feb 1998 17:44:24 +0000 (17:44 +0000)
    The diff looks so simple and easy. But to find it wasn't fun.

    It must have been there for a long time. What happened:

    When a tuple in one of some central catalogs was updated, the
    referenced  relation  got flushed, so it would be reopened on
    the next access (to reflect new  triggers,  rules  and  table
    structure changes into the relation cache).

    Some  data  (the  tupleDescriptor e.g.) is used in the system
    cache too. So when a relation is subject to the system cache,
    this  must know too that a cached system relation got flushed
    because the tupleDesc data gets freed during the flush!

    For the GRANT/REVOKE on pg_class it was  slightly  different.
    There  is some local data in inval.c that gets initialized on
    the first invalidation of a tuple in some  central  catalogs.
    This  needs a SysCache lookup in pg_class. But when the first
    of all commands is a GRANT on pg_class,  exactly  the  needed
    tuple is the one actually invalidated. So I added little code
    snippets that the initialization of the  local  variables  in
    inval.c will already happen during InitPostgres().

src/backend/utils/cache/catcache.c
src/backend/utils/cache/inval.c
src/backend/utils/cache/relcache.c
src/backend/utils/init/postinit.c
src/include/utils/catcache.h
src/include/utils/inval.h

index 616d875dc3fb2762cd5574f58c4f0391680b68db..36a617d8ae07d4a934f779aed0fae326bbe842e8 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.22 1998/02/11 19:12:47 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.23 1998/02/23 17:43:19 scrappy Exp $
  *
  * Notes:
  *             XXX This needs to use exception.h to handle recovery when
@@ -620,6 +620,29 @@ ResetSystemCache()
        MemoryContextSwitchTo(oldcxt);
 }
 
+/* --------------------------------
+ *             SystemCacheRelationFlushed
+ *
+ *     RelationFlushRelation() frees some information referenced in the
+ *     cache structures. So we get informed when this is done and arrange
+ *     for the next SearchSysCache() call that this information is setup
+ *     again.
+ * --------------------------------
+ */
+void
+SystemCacheRelationFlushed(Oid relId)
+{
+       struct catcache *cache;
+
+       for (cache = Caches; PointerIsValid(cache); cache = cache->cc_next)
+       {
+               if (cache->relationId == relId)
+               {
+                       cache->relationId = InvalidOid;
+               }
+       }
+}
+
 /* --------------------------------
  *             InitIndexedSysCache
  *
index e7b44380ab8f3ef3ee3b9a58fe2a63458c1d3f51..20762257e8946dcf70f44bc66271d7a860eda45e 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.9 1997/11/17 16:59:22 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.10 1998/02/23 17:43:23 scrappy Exp $
  *
  * Note - this code is real crufty...
  *
@@ -512,6 +512,20 @@ RelationInvalidateRelationCache(Relation relation,
        (*function) (relationId, objectId);
 }
 
+
+/*
+ *     InitLocalInvalidateData
+ *
+ *     Setup this before anything could ever get invalid!
+ *     Called by InitPostgres();
+ */
+void
+InitLocalInvalidateData()
+{
+       ValidateHacks();
+}
+
+
 /*
  * DiscardInvalid --
  *             Causes the invalidated cache state to be discarded.
index 28d9848f7b520c707554214686b379843fff0cde..f40d5a3fdbcafb171f8ec7de4047650050947a51 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.35 1998/01/31 04:38:52 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.36 1998/02/23 17:43:25 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -65,6 +65,7 @@
 #include "utils/relcache.h"
 #include "utils/hsearch.h"
 #include "utils/relcache.h"
+#include "utils/catcache.h"
 
 #include "catalog/catname.h"
 #include "catalog/catalog.h"
@@ -1344,6 +1345,7 @@ RelationFlushRelation(Relation *relationPtr,
                RelationCacheDelete(relation);
 
                FreeTupleDesc(relation->rd_att);
+               SystemCacheRelationFlushed(relation->rd_id);
 
                FreeTriggerDesc(relation);
 
index e3ec4131be448a6bd543179692a4314f769d2faf..2cd2a83b3c25115a7607fc55310d45f77281b560 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.22 1998/01/29 03:23:28 scrappy Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.23 1998/02/23 17:43:53 scrappy Exp $
  *
  * NOTES
  *             InitPostgres() is the function called from PostgresMain
@@ -62,6 +62,7 @@
 #include "utils/elog.h"
 #include "utils/palloc.h"
 #include "utils/mcxt.h"                        /* for EnableMemoryContext, etc. */
+#include "utils/inval.h"
 
 #include "catalog/catname.h"
 #include "catalog/pg_database.h"
@@ -586,6 +587,12 @@ InitPostgres(char *name)           /* database name */
         */
        InitUserid();
 
+       /* ----------------
+        *       initialize local data in cache invalidation stuff
+        * ----------------
+        */
+       InitLocalInvalidateData();
+
        /* ----------------
         *      ok, all done, now let's make sure we don't do it again.
         * ----------------
index 81215d098748bebdd51cef7b2b0bacfd6854a84b..e32035b7494376efa38718405b5c2cc07c95e892 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catcache.h,v 1.9 1998/01/24 22:50:34 momjian Exp $
+ * $Id: catcache.h,v 1.10 1998/02/23 17:44:22 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -66,6 +66,7 @@ extern GlobalMemory CacheCxt;
 extern void CatalogCacheIdInvalidate(int cacheId, Index hashIndex,
                                                 ItemPointer pointer);
 extern void ResetSystemCache(void);
+extern void SystemCacheRelationFlushed(Oid relId);
 extern CatCache * InitSysCache(char *relname, char *indname, int id, int nkeys,
                         int key[], HeapTuple (*iScanfuncP) ());
 extern HeapTuple SearchSysCache(struct catcache * cache, Datum v1, Datum v2,
index 06ebf21927efccdb802def0250b21ceda8df91c1..a487e88a74bf7d77990b3d98937f00bbb2d22831 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: inval.h,v 1.7 1997/09/08 21:55:08 momjian Exp $
+ * $Id: inval.h,v 1.8 1998/02/23 17:44:24 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -16,6 +16,8 @@
 #include <access/htup.h>
 #include <utils/rel.h>
 
+extern void InitLocalInvalidateData(void);
+
 extern void DiscardInvalid(void);
 
 extern void RegisterInvalid(bool send);