From 11d1e623b5be94d08c79aa7518f1abbab63e78a8 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Tue, 11 Oct 2022 12:51:19 +0200 Subject: [PATCH] satellite/metabase/segmentloop: don't do rate limiting if disabled We have a code to limit segments loop in case it will hit DB to hard but so far we didn't use this loop feature in production. This is a simple change to avoid logic responsible for rate limiting and its monitoring if limiting is disabled (RateLimit = 0) Change-Id: I43e07b407c6e65cf252303159d052eef250d1bea --- satellite/metabase/segmentloop/service.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/satellite/metabase/segmentloop/service.go b/satellite/metabase/segmentloop/service.go index ca71c641f..5f1cde456 100644 --- a/satellite/metabase/segmentloop/service.go +++ b/satellite/metabase/segmentloop/service.go @@ -438,10 +438,6 @@ func (loop *Service) iterateSegments(ctx context.Context, observers []*observerC rateLimiter := rate.NewLimiter(rate.Limit(loop.config.RateLimit), 1) - if loop.config.RateLimit == 0 { - rateLimiter = rate.NewLimiter(rate.Inf, 1) - } - limit := loop.config.ListLimit if limit <= 0 || limit > batchsizeLimit { limit = batchsizeLimit @@ -474,15 +470,17 @@ func (loop *Service) iterateSegments(ctx context.Context, observers []*observerC return err } - timer := mon.Timer("iterateLoopSegmentsRateLimit").Start() - if err := rateLimiter.Wait(ctx); err != nil { - // We don't really execute concurrent batches so we should never - // exceed the burst size of 1 and this should never happen. - // We can also enter here if the context is cancelled. + if loop.config.RateLimit > 0 { + timer := mon.Timer("iterateLoopSegmentsRateLimit").Start() + if err := rateLimiter.Wait(ctx); err != nil { + // We don't really execute concurrent batches so we should never + // exceed the burst size of 1 and this should never happen. + // We can also enter here if the context is cancelled. + timer.Stop() + return err + } timer.Stop() - return err } - timer.Stop() observers = withObservers(ctx, observers, func(ctx context.Context, observer *observerContext) bool { segment := Segment(entry)