From 79c2af13540ac39d449e8d97f3b573b30dcc33b0 Mon Sep 17 00:00:00 2001 From: ekexium Date: Thu, 10 Oct 2024 12:01:59 +0800 Subject: [PATCH] fix typo and refactor Signed-off-by: ekexium --- txnkv/transaction/2pc.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/txnkv/transaction/2pc.go b/txnkv/transaction/2pc.go index 22df9a8a3..1004f38ef 100644 --- a/txnkv/transaction/2pc.go +++ b/txnkv/transaction/2pc.go @@ -1342,14 +1342,17 @@ func keepAlive( tm.close() } return + continue } - } else { - keepFail = 0 - metrics.TxnHeartBeatHistogramOK.Observe(time.Since(startTime).Seconds()) } - // broadcast to all stores - if err != nil && isPipelinedTxn { + keepFail = 0 + metrics.TxnHeartBeatHistogramOK.Observe(time.Since(startTime).Seconds()) + // Broadcast to all stores only when the heartbeat succeeds. + // This ensures that PK is the single source of truth for transaction status on the + // TiKV side. It prevents potential inconsistencies where the cached information might + // be more up-to-date than the info stored in the PK. + if isPipelinedTxn { broadcastToAllStores( c.txn, c.store,