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,
user_mapping->userid, foreign_server->serverid);
}
- cluster->umTupleId = tup->t_self;
+ scstamp_set(USERMAPPINGOID, &cluster->umStamp, tup);
+
ReleaseSysCache(tup);
/*
* functions.
*/
static void
-ClusterSyscacheCallback(Datum arg, int cacheid, ItemPointer tuplePtr)
+ClusterSyscacheCallback(Datum arg, int cacheid, SCInvalArg newStamp)
{
ProxyCluster *cluster;
/* 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;
}
}
}
#include <utils/lsyscache.h>
#include <utils/memutils.h>
#include <utils/syscache.h>
+
#include "rowstamp.h"
#include <libpq-fe.h>
* 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;
#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
+