Skip to content

Commit

Permalink
Merge pull request #87923 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…21.2-87914

release-21.2: kvserver/reports: cancel context on stopper quiescence
  • Loading branch information
erikgrinaker authored Sep 14, 2022
2 parents a4b0f48 + cff8873 commit 02d30aa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/kv/kvserver/reports/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ func (stats *Reporter) Start(ctx context.Context, stopper *stop.Stopper) {
stats.frequencyMu.interval = ReporterInterval.Get(&stats.settings.SV)
})
_ = stopper.RunAsyncTask(ctx, "stats-reporter", func(ctx context.Context) {
ctx = logtags.AddTag(ctx, "replication-reporter", nil /* value */)
ctx, cancel := stopper.WithCancelOnQuiesce(ctx)
defer cancel()

var timer timeutil.Timer
defer timer.Stop()
ctx = logtags.AddTag(ctx, "replication-reporter", nil /* value */)

replStatsSaver := makeReplicationStatsReportSaver()
constraintsSaver := makeReplicationConstraintStatusReportSaver()
Expand Down Expand Up @@ -159,6 +162,8 @@ func (stats *Reporter) Start(ctx context.Context, stopper *stop.Stopper) {
case <-timerCh:
timer.Read = true
case <-changeCh:
case <-ctx.Done():
return
case <-stopper.ShouldQuiesce():
return
}
Expand Down Expand Up @@ -591,6 +596,11 @@ func visitRanges(
break
}

// Check for context cancellation.
if err := ctx.Err(); err != nil {
return err
}

newKey, err := resolver.resolveRange(ctx, &rd, cfg)
if err != nil {
return err
Expand Down

0 comments on commit 02d30aa

Please sign in to comment.