Sync with cache invalidation changes in 9.2
authorMarko Kreen <markokr@gmail.com>
Mon, 27 Feb 2012 00:09:22 +0000 (02:09 +0200)
committerMarko Kreen <markokr@gmail.com>
Wed, 7 Mar 2012 20:57:28 +0000 (22:57 +0200)
src/cluster.c
src/plproxy.h
src/rowstamp.h

index de803adb533417001f70acc3751ebbf65c17e55f..e823defbfad8bb4c8597ee2f66a5fd65657c5bb9 100644 (file)
@@ -531,7 +531,7 @@ reload_sqlmed_cluster(ProxyFunction *func, ProxyCluster *cluster,
     if (!HeapTupleIsValid(tup))
         elog(ERROR, "cache lookup failed for foreign server %u", foreign_server->serverid);
 
-       cluster->clusterTupleId = tup->t_self;
+       scstamp_set(FOREIGNSERVEROID, &cluster->clusterStamp, tup);
        ReleaseSysCache(tup);
 
     tup = SearchSysCache(USERMAPPINGUSERSERVER,
@@ -551,7 +551,8 @@ reload_sqlmed_cluster(ProxyFunction *func, ProxyCluster *cluster,
                                user_mapping->userid, foreign_server->serverid);
        }
 
-       cluster->umTupleId = tup->t_self;
+       scstamp_set(USERMAPPINGOID, &cluster->umStamp, tup);
+
        ReleaseSysCache(tup);
 
        /*
@@ -684,7 +685,7 @@ determine_compat_mode(ProxyCluster *cluster)
  * functions.
  */
 static void
-ClusterSyscacheCallback(Datum arg, int cacheid, ItemPointer tuplePtr)
+ClusterSyscacheCallback(Datum arg, int cacheid, SCInvalArg newStamp)
 {
        ProxyCluster *cluster;
 
@@ -695,25 +696,23 @@ ClusterSyscacheCallback(Datum arg, int cacheid, ItemPointer tuplePtr)
                        /* already invalidated */
                        continue;
                }
-               else if (!tuplePtr)
-               {
-                       /* invalidate all */
-                       cluster->needs_reload = true;
-               }
                else if (!cluster->sqlmed_cluster)
                {
                        /* allow new SQL/MED servers to override compat definitions */
-                       cluster->needs_reload = (cacheid == FOREIGNSERVEROID);
+                       if (cacheid == FOREIGNSERVEROID)
+                               cluster->needs_reload = true;
                }
                else if (cacheid == USERMAPPINGOID)
                {
                        /* user mappings changed */
-                       cluster->needs_reload = ItemPointerEquals(tuplePtr, &cluster->umTupleId);
+                       if (scstamp_check(cacheid, &cluster->umStamp, newStamp))
+                               cluster->needs_reload = true;
                }
                else if (cacheid == FOREIGNSERVEROID)
                {
                        /* server definitions changed */
-                       cluster->needs_reload = ItemPointerEquals(tuplePtr, &cluster->clusterTupleId);
+                       if (scstamp_check(cacheid, &cluster->clusterStamp, newStamp))
+                               cluster->needs_reload = true;
                }
        }
 }
index 72b5ae4c9f2a375b4b3a89932a0a550a350432c0..c82fb11ae364d3e33cd4ed7f03d60bd4f7767e0a 100644 (file)
@@ -54,6 +54,7 @@
 #include <utils/lsyscache.h>
 #include <utils/memutils.h>
 #include <utils/syscache.h>
+
 #include "rowstamp.h"
 
 #include <libpq-fe.h>
@@ -196,8 +197,8 @@ typedef struct ProxyCluster
         * SQL/MED clusters: TIDs of the foreign server and user mapping catalog tuples.
         * Used in to perform cluster invalidation in syscache callbacks.
         */
-       ItemPointerData         clusterTupleId;
-       ItemPointerData         umTupleId;
+       SysCacheStamp clusterStamp;
+       SysCacheStamp umStamp;
 
        /* notice processing: provide info about currently executing function */
        struct ProxyFunction    *cur_func;
index acd51b29bbcb35967e284e8f3592c48393cc96be..37ca3784ef925ad58064ce240742d9d5b917a993 100644 (file)
@@ -48,3 +48,52 @@ static inline bool plproxy_check_stamp(RowStamp *stamp, HeapTuple tup)
 
 #endif
 
+/*
+ * SyscacheCallback check changed in 9.2.
+ */
+
+#if PG_VERSION_NUM >= 90200
+
+typedef uint32 SCInvalArg;
+typedef struct SysCacheStamp {
+       uint32 cacheid;
+       uint32 hashValue;
+} SysCacheStamp;
+
+static inline void scstamp_set(int cache, SysCacheStamp *stamp, HeapTuple tup)
+{
+       Oid oid = HeapTupleGetOid(tup);
+       stamp->cacheid = cache;
+       stamp->hashValue = GetSysCacheHashValue1(cache, oid);
+}
+
+static inline bool scstamp_check(int cache, SysCacheStamp *stamp, uint32 hashValue)
+{
+       if (cache != stamp->cacheid)
+               elog(WARNING, "cache id mismatch: stamp:%d cur:%d", stamp->cacheid, cache);
+       return !hashValue || stamp->hashValue == hashValue;
+}
+
+#else
+
+/*
+ * Pre-9.2 cache invalidation.
+ */
+
+typedef ItemPointer SCInvalArg;
+typedef struct SysCacheStamp {
+       ItemPointerData     tupleId;
+} SysCacheStamp;
+
+static inline void scstamp_set(int cache, SysCacheStamp *stamp, HeapTuple tup)
+{
+       stamp->tupleId = tup->t_self;
+}
+
+static inline bool scstamp_check(int cache, SysCacheStamp *stamp, ItemPointer scrow)
+{
+       return !scrow || ItemPointerEquals(&stamp->tupleId, scrow);
+}
+
+#endif
+