Skip to content

Commit

Permalink
Add txn write conflict metrics
Browse files Browse the repository at this point in the history
Signed-off-by: sujuntao <juntao.su@foxmail.com>
  • Loading branch information
sujuntao committed Feb 10, 2025
1 parent ec9ad0f commit c87174e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions txnkv/transaction/pipelined_flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions txnkv/transaction/prewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ func (handler *prewrite1BatchReqHandler) extractKeyErrs(keyErrs []*kvrpcpb.KeyEr
// TiKV returns lock.TTL = 0, and we still need to resolve the lock.
if (lock.TxnID > handler.committer.startTS && !handler.committer.isPessimistic) ||
handler.committer.txn.prewriteEncounterLockPolicy == NoResolvePolicy {
metrics.LockResolverCountWithWriteConflict.Inc()
return nil, tikverr.NewErrWriteConflictWithArgs(
handler.committer.startTS,
lock.TxnID,
Expand Down

0 comments on commit c87174e

Please # to comment.