From 0bcadf81495789fabb19b805a3ca2bb0df77dcc6 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 27 Feb 2012 02:09:22 +0200 Subject: [PATCH] Sync with cache invalidation changes in 9.2 --- src/cluster.c | 21 ++++++++++----------- src/plproxy.h | 5 +++-- src/rowstamp.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index de803ad..e823def 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -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; } } } diff --git a/src/plproxy.h b/src/plproxy.h index 72b5ae4..c82fb11 100644 --- a/src/plproxy.h +++ b/src/plproxy.h @@ -54,6 +54,7 @@ #include #include #include + #include "rowstamp.h" #include @@ -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; diff --git a/src/rowstamp.h b/src/rowstamp.h index acd51b2..37ca378 100644 --- a/src/rowstamp.h +++ b/src/rowstamp.h @@ -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 + -- 2.39.5