From 15abaa4ceb758f043e46984f37c79350de25e49f 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..11c1ed0bd 100644 --- a/txnkv/transaction/2pc.go +++ b/txnkv/transaction/2pc.go @@ -1343,13 +1343,16 @@ func keepAlive( } return } - } else { - keepFail = 0 - metrics.TxnHeartBeatHistogramOK.Observe(time.Since(startTime).Seconds()) + continue } - // 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,