From d7a118335af7231b407a5ca65b65885d9ed37ddf Mon Sep 17 00:00:00 2001 From: starrysky Date: Mon, 8 Jun 2026 17:12:09 +0800 Subject: [PATCH] Fix standby cache persistence checks during failover --- tx_service/include/cc/object_cc_map.h | 3 ++- tx_service/src/cc/cc_entry.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tx_service/include/cc/object_cc_map.h b/tx_service/include/cc/object_cc_map.h index f69ba939..d8e3545c 100644 --- a/tx_service/include/cc/object_cc_map.h +++ b/tx_service/include/cc/object_cc_map.h @@ -1909,7 +1909,8 @@ class ObjectCcMap : public TemplateCcMap decoded_key.Deserialize(key_str->data(), offset, KeySchema()); const KeyT *look_key = &decoded_key; - if (Sharder::Instance().StandbyNodeTerm() >= 0 && + if ((Sharder::Instance().StandbyNodeTerm() >= 0 || + Sharder::Instance().CandidateStandbyNodeTerm() >= 0) && Sharder::Instance().GetDataStoreHandler()->IsSharedStorage() && commit_ts < Sharder::Instance().NativeNodeGroupCkptTs()) { diff --git a/tx_service/src/cc/cc_entry.cpp b/tx_service/src/cc/cc_entry.cpp index 4610841b..a925e2fa 100644 --- a/tx_service/src/cc/cc_entry.cpp +++ b/tx_service/src/cc/cc_entry.cpp @@ -60,10 +60,16 @@ void VersionedLruEntry::SetCommitTsPayloadStatus( template bool VersionedLruEntry::IsPersistent() const { - if (Sharder::Instance().StandbyNodeTerm() >= 0 && + const int64_t standby_term = Sharder::Instance().StandbyNodeTerm(); + const int64_t candidate_standby_term = + Sharder::Instance().CandidateStandbyNodeTerm(); + if ((standby_term >= 0 || candidate_standby_term >= 0) && Sharder::Instance().GetDataStoreHandler()->IsSharedStorage()) { - // If this is a follower with shared kv, check the ng leader's ckpt_ts. + // For shared-storage standby cache, entries are persistent once the + // primary's checkpoint ts has advanced past the entry's commit ts. This + // must apply during candidate-standby as well, otherwise entries loaded + // while following cannot be reclaimed before snapshot sync finishes. return CommitTs() <= Sharder::Instance().NativeNodeGroupCkptTs(); }