@@ -256,12 +256,9 @@ func (ds *DistSender) RangeFeedSpans(
256
256
}
257
257
// Prior to spawning goroutine to process this feed, acquire catchup scan quota.
258
258
// This quota acquisition paces the rate of new goroutine creation.
259
- catchupRes , err := acquireCatchupScanQuota (ctx , & ds .st .SV , & catchupSem , metrics )
260
- if err != nil {
261
- active .release ()
259
+ if err := active .acquireCatchupScanQuota (ctx , & ds .st .SV , & catchupSem , metrics ); err != nil {
262
260
return err
263
261
}
264
- active .catchupRes = catchupRes
265
262
if log .V (1 ) {
266
263
log .Infof (ctx , "RangeFeed starting for span %s@%s (quota acquired in %s)" ,
267
264
span , sri .startAfter , timeutil .Since (acquireStart ))
@@ -518,7 +515,6 @@ func newActiveRangeFeed(
518
515
Span : span ,
519
516
StartAfter : startAfter ,
520
517
CreatedTime : timeutil .Now (),
521
- InCatchup : true ,
522
518
},
523
519
}
524
520
@@ -703,24 +699,28 @@ func (a catchupAlloc) Release() {
703
699
a ()
704
700
}
705
701
706
- func acquireCatchupScanQuota (
702
+ func ( a * activeRangeFeed ) acquireCatchupScanQuota (
707
703
ctx context.Context ,
708
704
sv * settings.Values ,
709
705
catchupSem * limit.ConcurrentRequestLimiter ,
710
706
metrics * DistSenderRangeFeedMetrics ,
711
- ) ( catchupAlloc , error ) {
707
+ ) error {
712
708
// Indicate catchup scan is starting; Before potentially blocking on a semaphore, take
713
709
// opportunity to update semaphore limit.
714
710
catchupSem .SetLimit (maxConcurrentCatchupScans (sv ))
715
711
res , err := catchupSem .Begin (ctx )
716
712
if err != nil {
717
- return nil , err
713
+ return err
718
714
}
719
715
metrics .RangefeedCatchupRanges .Inc (1 )
720
- return func () {
716
+ a . catchupRes = func () {
721
717
metrics .RangefeedCatchupRanges .Dec (1 )
722
718
res .Release ()
723
- }, nil
719
+ }
720
+ a .Lock ()
721
+ defer a .Unlock ()
722
+ a .InCatchup = true
723
+ return nil
724
724
}
725
725
726
726
// nweTransportForRange returns Transport for the specified range descriptor.
0 commit comments