From 7edda5e2a454e760ec1905cd93ae774e06a66cc4 Mon Sep 17 00:00:00 2001 From: justbk <249396768@qq.com> Date: Tue, 24 May 2022 21:47:43 +0800 Subject: [PATCH] repair GSC no cache issue --- .../backend/utils/cache/knl_globalsysdbcache.cpp | 11 ++++++++++- .../backend/utils/cache/knl_globalsystabcache.cpp | 2 +- .../backend/utils/cache/knl_localpartdefcache.cpp | 6 +++--- .../backend/utils/cache/knl_localsystupcache.cpp | 6 +++--- .../backend/utils/cache/knl_localtabdefcache.cpp | 6 +++--- src/gausskernel/storage/access/transam/xlog.cpp | 2 ++ src/include/utils/knl_globalsysdbcache.h | 7 ++++++- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/common/backend/utils/cache/knl_globalsysdbcache.cpp b/src/common/backend/utils/cache/knl_globalsysdbcache.cpp index 3c4b6d562..ce0b7f316 100644 --- a/src/common/backend/utils/cache/knl_globalsysdbcache.cpp +++ b/src/common/backend/utils/cache/knl_globalsysdbcache.cpp @@ -1272,9 +1272,18 @@ int ResizeHashBucket(int origin_nbucket, DynamicHashBucketStrategy strategy) return cc_nbuckets; } +void NotifyGscRecoveryStarted() +{ + if (!EnableGlobalSysCache()) { + return; + } + g_instance.global_sysdbcache.recovery_finished = false; + +} + void NotifyGscRecoveryFinished() { if (EnableGlobalSysCache()) { g_instance.global_sysdbcache.recovery_finished = true; } -} \ No newline at end of file +} diff --git a/src/common/backend/utils/cache/knl_globalsystabcache.cpp b/src/common/backend/utils/cache/knl_globalsystabcache.cpp index cc1400519..a87d5475e 100644 --- a/src/common/backend/utils/cache/knl_globalsystabcache.cpp +++ b/src/common/backend/utils/cache/knl_globalsystabcache.cpp @@ -183,7 +183,7 @@ void GlobalSysTabCache::InvalidTuples(int cache_id, uint32 hash_value, bool rese /* maybe upgrade from version before v5r2c00, the cacheid is out of order * whatever, we cache nothing except relmap, so just ignore the catcache invalmsg */ - if (unlikely(!g_instance.global_sysdbcache.recovery_finished) && m_global_systupcaches[cache_id] == NULL) { + if (unlikely(!g_instance.global_sysdbcache.recovery_finished && m_global_systupcaches[cache_id] == NULL)) { return; } diff --git a/src/common/backend/utils/cache/knl_localpartdefcache.cpp b/src/common/backend/utils/cache/knl_localpartdefcache.cpp index a12167b92..bd94224f2 100644 --- a/src/common/backend/utils/cache/knl_localpartdefcache.cpp +++ b/src/common/backend/utils/cache/knl_localpartdefcache.cpp @@ -74,7 +74,7 @@ Partition LocalPartDefCache::SearchPartitionFromGlobalCopy(Oid part_oid) if (!g_instance.global_sysdbcache.hot_standby) { return NULL; } - if (unlikely(!g_instance.global_sysdbcache.recovery_finished)) { + if (unlikely(!IsPrimaryRecoveryFinished())) { return NULL; } uint32 hash_value = oid_hash((void *)&(part_oid), sizeof(Oid)); @@ -165,7 +165,7 @@ static bool IsPartOidStoreInGlobal(Oid part_oid) if (!g_instance.global_sysdbcache.hot_standby) { return false; } - if (unlikely(!g_instance.global_sysdbcache.recovery_finished)) { + if (unlikely(!IsPrimaryRecoveryFinished())) { return false; } if (g_instance.global_sysdbcache.StopInsertGSC()) { @@ -456,4 +456,4 @@ Partition LocalPartDefCache::PartitionIdGetPartition(Oid part_oid, StorageType s } return pd; -} \ No newline at end of file +} diff --git a/src/common/backend/utils/cache/knl_localsystupcache.cpp b/src/common/backend/utils/cache/knl_localsystupcache.cpp index 132aefc30..f2148476a 100644 --- a/src/common/backend/utils/cache/knl_localsystupcache.cpp +++ b/src/common/backend/utils/cache/knl_localsystupcache.cpp @@ -433,7 +433,7 @@ LocalCatCTup *LocalSysTupCache::SearchTupleFromGlobal(Datum *arguments, uint32 h bool bypass_gsc = HistoricSnapshotActive() || m_global_systupcache->enable_rls || !g_instance.global_sysdbcache.hot_standby || - unlikely(!g_instance.global_sysdbcache.recovery_finished); + unlikely(!IsPrimaryRecoveryFinished()); if (invalid_entries.ExistTuple(hash_value) || bypass_gsc) { global_ct = m_global_systupcache->SearchTupleFromFile(hash_value, arguments, true); } else { @@ -585,7 +585,7 @@ LocalCatCList *LocalSysTupCache::SearchListFromGlobal(int nkeys, Datum *argument bool bypass_gsc = HistoricSnapshotActive() || m_global_systupcache->enable_rls || !g_instance.global_sysdbcache.hot_standby || - unlikely(!g_instance.global_sysdbcache.recovery_finished); + unlikely(!IsPrimaryRecoveryFinished()); GlobalCatCList *global_cl; if (invalid_entries.ExistList() || bypass_gsc) { global_cl = m_global_systupcache->SearchListFromFile(hash_value, nkeys, arguments, true); @@ -703,7 +703,7 @@ LocalCatCTup *LocalSysTupCache::SearchTupleFromGlobalForProcAllArgs( bool bypass_gsc = HistoricSnapshotActive() || m_global_systupcache->enable_rls || !g_instance.global_sysdbcache.hot_standby || - unlikely(!g_instance.global_sysdbcache.recovery_finished); + unlikely(!IsPrimaryRecoveryFinished()); if (invalid_entries.ExistTuple(hash_value) || bypass_gsc) { global_ct = m_global_systupcache->SearchTupleFromFileWithArgModes(hash_value, arguments, argModes, true); } else { diff --git a/src/common/backend/utils/cache/knl_localtabdefcache.cpp b/src/common/backend/utils/cache/knl_localtabdefcache.cpp index 6b989cde8..9e03d00b6 100644 --- a/src/common/backend/utils/cache/knl_localtabdefcache.cpp +++ b/src/common/backend/utils/cache/knl_localtabdefcache.cpp @@ -93,7 +93,7 @@ Relation LocalTabDefCache::SearchRelationFromGlobalCopy(Oid rel_oid) if (!g_instance.global_sysdbcache.hot_standby) { return NULL; } - if (unlikely(!g_instance.global_sysdbcache.recovery_finished)) { + if (unlikely(!IsPrimaryRecoveryFinished())) { return NULL; } uint32 hash_value = oid_hash((void *)&(rel_oid), sizeof(Oid)); @@ -190,7 +190,7 @@ static bool IsRelOidStoreInGlobal(Oid rel_oid) if (!g_instance.global_sysdbcache.hot_standby) { return false; } - if (unlikely(!g_instance.global_sysdbcache.recovery_finished)) { + if (unlikely(!IsPrimaryRecoveryFinished())) { return false; } if (g_instance.global_sysdbcache.StopInsertGSC()) { @@ -1137,4 +1137,4 @@ void LocalTabDefCache::ResetInitFlag() m_is_inited_phase3 = false; m_db_id = InvalidOid; -} \ No newline at end of file +} diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 158c4ab49..0280d36cf 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -8965,6 +8965,8 @@ void StartupXLOG(void) g_instance.comm_cxt.predo_cxt.redoPf.redo_done_time = 0; pg_atomic_write_u32(&(g_instance.comm_cxt.localinfo_cxt.is_finish_redo), 0); + NotifyGscRecoveryStarted(); + /* * Initialize WAL insert status array and the flush index - lastWalStatusEntryFlushed. */ diff --git a/src/include/utils/knl_globalsysdbcache.h b/src/include/utils/knl_globalsysdbcache.h index 05f194960..94d0674f6 100644 --- a/src/include/utils/knl_globalsysdbcache.h +++ b/src/include/utils/knl_globalsysdbcache.h @@ -229,10 +229,15 @@ private: bool m_syscache_relids[FirstNormalObjectId]; }; +void NotifyGscRecoveryStarted(); void NotifyGscRecoveryFinished(); extern Datum gs_gsc_dbstat_info(PG_FUNCTION_ARGS); extern Datum gs_gsc_clean(PG_FUNCTION_ARGS); extern Datum gs_gsc_catalog_detail(PG_FUNCTION_ARGS); extern Datum gs_gsc_table_detail(PG_FUNCTION_ARGS); extern int ResizeHashBucket(int origin_nbucket, DynamicHashBucketStrategy strategy); -#endif \ No newline at end of file + +/* only primary node check recovery, recovery from upgrade may have misorder cacheids */ +#define IsPrimaryRecoveryFinished() \ + (g_instance.global_sysdbcache.recovery_finished || t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE) +#endif