Skip to content

Commit

Permalink
kvcoord: small refactor
Browse files Browse the repository at this point in the history
Lift a defer() into a wrapper function.

Release note: None
  • Loading branch information
andreimatei committed Jul 23, 2021
1 parent 7ee6bd6 commit 94ac161
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pkg/kv/kvclient/kvcoord/txn_interceptor_pipeliner.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,23 +488,29 @@ func (tp *txnPipeliner) chainToInFlightWrites(ba roachpb.BatchRequest) roachpb.B
func (tp *txnPipeliner) updateLockTracking(
ctx context.Context, ba roachpb.BatchRequest, br *roachpb.BatchResponse,
) {
tp.updateLockTrackingInner(ctx, ba, br)

// Deal with compacting the lock spans.

// After adding new writes to the lock footprint, check whether we need to
// condense the set to stay below memory limits.
defer func() {
alreadyCondensed := tp.lockFootprint.condensed
condensed := tp.lockFootprint.maybeCondense(ctx, tp.riGen, trackedWritesMaxSize.Get(&tp.st.SV))
if condensed && !alreadyCondensed {
if tp.condensedIntentsEveryN.ShouldLog() || log.ExpensiveLogEnabled(ctx, 2) {
log.Warningf(ctx,
"a transaction has hit the intent tracking limit (kv.transaction.max_intents_bytes); "+
"is it a bulk operation? Intent cleanup will be slower. txn: %s ba: %s",
ba.Txn, ba.Summary())
}
tp.txnMetrics.TxnsWithCondensedIntents.Inc(1)
tp.txnMetrics.TxnsWithCondensedIntentsGauge.Inc(1)
alreadyCondensed := tp.lockFootprint.condensed
condensed := tp.lockFootprint.maybeCondense(ctx, tp.riGen, trackedWritesMaxSize.Get(&tp.st.SV))
if condensed && !alreadyCondensed {
if tp.condensedIntentsEveryN.ShouldLog() || log.ExpensiveLogEnabled(ctx, 2) {
log.Warningf(ctx,
"a transaction has hit the intent tracking limit (kv.transaction.max_intents_bytes); "+
"is it a bulk operation? Intent cleanup will be slower. txn: %s ba: %s",
ba.Txn, ba.Summary())
}
}()
tp.txnMetrics.TxnsWithCondensedIntents.Inc(1)
tp.txnMetrics.TxnsWithCondensedIntentsGauge.Inc(1)
}
}

func (tp *txnPipeliner) updateLockTrackingInner(
ctx context.Context, ba roachpb.BatchRequest, br *roachpb.BatchResponse,
) {
// If the request failed, add all lock acquisitions attempts directly to the
// lock footprint. This reduces the likelihood of dangling locks blocking
// concurrent requests for extended periods of time. See #3346.
Expand Down

0 comments on commit 94ac161

Please sign in to comment.