From 4da56ae36a1bab3494136c73ecc99ef7970b69b8 Mon Sep 17 00:00:00 2001 From: Arul Ajmani Date: Wed, 22 Mar 2023 22:54:20 +0000 Subject: [PATCH] txnwait: do not require vmodule to log deadlocks in a workload Deadlocks in a workload are rare (and bad) enough that they should be logged at the level of Info, instead of under vmodule. Epic: none Release note: None --- pkg/kv/kvserver/txnwait/queue.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/kv/kvserver/txnwait/queue.go b/pkg/kv/kvserver/txnwait/queue.go index 0d2267073300..5ae4180ecd0f 100644 --- a/pkg/kv/kvserver/txnwait/queue.go +++ b/pkg/kv/kvserver/txnwait/queue.go @@ -227,8 +227,9 @@ type TestingKnobs struct { // // Queue is thread safe. type Queue struct { - cfg Config - mu struct { + cfg Config + every log.EveryN // dictates logging for transaction aborts resulting from deadlock detection + mu struct { syncutil.RWMutex txns map[uuid.UUID]*pendingTxn queries map[uuid.UUID]*waitingQueries @@ -237,7 +238,10 @@ type Queue struct { // NewQueue instantiates a new Queue. func NewQueue(cfg Config) *Queue { - return &Queue{cfg: cfg} + return &Queue{ + cfg: cfg, + every: log.Every(1 * time.Second), + } } // Enable allows transactions to be enqueued and waiting pushers @@ -719,9 +723,15 @@ func (q *Queue) waitForPush( // Break the deadlock if the pusher has higher priority. p1, p2 := pusheePriority, pusherPriority if p1 < p2 || (p1 == p2 && bytes.Compare(req.PusheeTxn.ID.GetBytes(), req.PusherTxn.ID.GetBytes()) < 0) { + // NB: It's useful to have logs indicating the transactions involved + // in a deadlock, but we don't want these to be too spammy. + level := log.Level(1) + if q.every.ShouldLog() { + level = 0 // will behave like a log.Infof + } log.VEventf( ctx, - 1, + level, "%s breaking deadlock by force push of %s; dependencies=%s", req.PusherTxn.ID.Short(), req.PusheeTxn.ID.Short(),