From 9dc066ebfdb6f4ae3d099b53150646aa64f01048 Mon Sep 17 00:00:00 2001 From: sujuntao Date: Tue, 7 Jan 2025 22:53:52 +0800 Subject: [PATCH] Add txn write conflict metrics Signed-off-by: sujuntao --- txnkv/transaction/pipelined_flush.go | 2 ++ txnkv/transaction/prewrite.go | 1 + 2 files changed, 3 insertions(+) diff --git a/txnkv/transaction/pipelined_flush.go b/txnkv/transaction/pipelined_flush.go index c745e538a5..f1f0bf8bd5 100644 --- a/txnkv/transaction/pipelined_flush.go +++ b/txnkv/transaction/pipelined_flush.go @@ -34,6 +34,7 @@ import ( "github.com/tikv/client-go/v2/internal/locate" "github.com/tikv/client-go/v2/internal/logutil" "github.com/tikv/client-go/v2/kv" + "github.com/tikv/client-go/v2/metrics" "github.com/tikv/client-go/v2/tikvrpc" "github.com/tikv/client-go/v2/txnkv/rangetask" "github.com/tikv/client-go/v2/txnkv/txnlock" @@ -244,6 +245,7 @@ func (action actionPipelinedFlush) handleSingleBatch( // TiKV will return a PessimisticLockNotFound error directly if it encounters a different lock. Otherwise, // TiKV returns lock.TTL = 0, and we still need to resolve the lock. if lock.TxnID > c.startTS && !c.isPessimistic { + metrics.LockResolverCountWithWriteConflict.Inc() return tikverr.NewErrWriteConflictWithArgs( c.startTS, lock.TxnID, diff --git a/txnkv/transaction/prewrite.go b/txnkv/transaction/prewrite.go index 21b84e8a39..4d7571533b 100644 --- a/txnkv/transaction/prewrite.go +++ b/txnkv/transaction/prewrite.go @@ -460,6 +460,7 @@ func (action actionPrewrite) handleSingleBatch( // TiKV returns lock.TTL = 0, and we still need to resolve the lock. if (lock.TxnID > c.startTS && !c.isPessimistic) || c.txn.prewriteEncounterLockPolicy == NoResolvePolicy { + metrics.LockResolverCountWithWriteConflict.Inc() return tikverr.NewErrWriteConflictWithArgs( c.startTS, lock.TxnID,