Skip to content

Commit

Permalink
lock_resolver (ticdc):only log when there are locks to reduce verbose…
Browse files Browse the repository at this point in the history
… log
  • Loading branch information
asddongmen committed May 11, 2024
1 parent 1a38104 commit 85796db
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions pkg/txnutil/lock_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package txnutil
import (
"bytes"
"context"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
Expand Down Expand Up @@ -51,22 +52,24 @@ func NewLockerResolver(
const scanLockLimit = 1024

func (r *resolver) Resolve(ctx context.Context, regionID uint64, maxVersion uint64) (err error) {
var lockCount int = 0
var totalLocks []*txnkv.Lock

log.Info("resolve lock starts",
zap.Uint64("regionID", regionID),
zap.Uint64("maxVersion", maxVersion),
zap.String("namespace", r.changefeed.Namespace),
zap.String("changefeed", r.changefeed.ID))
start := time.Now()

defer func() {
log.Info("resolve lock finishes",
zap.Uint64("regionID", regionID),
zap.Int("lockCount", lockCount),
zap.Uint64("maxVersion", maxVersion),
zap.String("namespace", r.changefeed.Namespace),
zap.String("changefeed", r.changefeed.ID),
zap.Error(err))
// Only log when there are locks or error to avoid log flooding.
if len(totalLocks) != 0 || err != nil {
cost := time.Since(start)
log.Info("resolve lock finishes",
zap.Uint64("regionID", regionID),
zap.Int("lockCount", len(totalLocks)),
zap.Any("locks", totalLocks),
zap.Uint64("maxVersion", maxVersion),
zap.String("namespace", r.changefeed.Namespace),
zap.String("changefeed", r.changefeed.ID),
zap.Duration("duration", cost),
zap.Error(err))
}
}()

// TODO test whether this function will kill active transaction
Expand Down Expand Up @@ -127,7 +130,7 @@ func (r *resolver) Resolve(ctx context.Context, regionID uint64, maxVersion uint
for i := range locksInfo {
locks[i] = txnkv.NewLock(locksInfo[i])
}
lockCount += len(locksInfo)
totalLocks = append(totalLocks, locks...)

_, err1 := r.kvStorage.GetLockResolver().ResolveLocks(bo, 0, locks)
if err1 != nil {
Expand Down

0 comments on commit 85796db

Please sign in to comment.