Skip to content

Commit

Permalink
Add read lock + increment right before sending series request
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Jung <[email protected]>
  • Loading branch information
justinjung04 committed Sep 11, 2023
1 parent 5cf96aa commit c6b1264
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/storegateway/bucket_stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,8 @@ func (u *BucketStores) Series(req *storepb.SeriesRequest, srv storepb.Store_Seri
defer spanLog.Span.Finish()

maxInflightRequests := u.cfg.BucketStore.MaxInflightRequests
if maxInflightRequests > 0 {
if u.inflightRequestCnt >= maxInflightRequests {
return ErrTooManyInflightRequests
}

u.incrementInflightRequestCnt()
defer u.decrementInflightRequestCnt()
if maxInflightRequests > 0 && u.getInflightRequestCnt() >= maxInflightRequests {
return ErrTooManyInflightRequests
}

userID := getUserIDFromGRPCContext(spanCtx)
Expand All @@ -330,6 +325,11 @@ func (u *BucketStores) Series(req *storepb.SeriesRequest, srv storepb.Store_Seri
return nil
}

if maxInflightRequests > 0 {
u.incrementInflightRequestCnt()
defer u.decrementInflightRequestCnt()
}

err = store.Series(req, spanSeriesServer{
Store_SeriesServer: srv,
ctx: spanCtx,
Expand All @@ -338,6 +338,12 @@ func (u *BucketStores) Series(req *storepb.SeriesRequest, srv storepb.Store_Seri
return err
}

func (u *BucketStores) getInflightRequestCnt() int {
u.inflightRequestMu.RLock()
defer u.inflightRequestMu.RUnlock()
return u.inflightRequestCnt
}

func (u *BucketStores) incrementInflightRequestCnt() {
u.inflightRequestMu.Lock()
u.inflightRequestCnt++
Expand Down

0 comments on commit c6b1264

Please sign in to comment.