Skip to content

Commit

Permalink
Skip loading cache for unneeded blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Apr 25, 2019
1 parent bac4ebc commit 6c373cc
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ func (s *BucketStore) SyncBlocks(ctx context.Context) error {
if err != nil {
return nil
}

inRange, err := s.isBlockInMinMaxRange(ctx, id)
if err != nil {
level.Warn(s.logger).Log("msg", "error parsing block range", "block", id, "err", err)
return nil
}

if !inRange {
return nil
}

allIDs[id] = struct{}{}

if b := s.getBlock(id); b != nil {
Expand Down Expand Up @@ -422,11 +433,6 @@ func (s *BucketStore) addBlock(ctx context.Context, id ulid.ULID) (err error) {
return errors.Wrap(err, "new bucket block")
}

// We check for blocks in configured minTime, maxTime range
if b.meta.MinTime < s.minTime.PrometheusTimestamp() || b.meta.MinTime > s.maxTime.PrometheusTimestamp() {
return nil
}

s.mtx.Lock()
defer s.mtx.Unlock()

Expand Down Expand Up @@ -1903,3 +1909,22 @@ func (s queryStats) merge(o *queryStats) *queryStats {

return &s
}

func (s *BucketStore) isBlockInMinMaxRange(ctx context.Context, id ulid.ULID) (bool, error) {
b := &bucketBlock{
logger: s.logger,
bucket: s.bucket,
id: id,
dir: s.dir,
}
if err := b.loadMeta(ctx, id); err != nil {
return false, err
}

// We check for blocks in configured minTime, maxTime range
if b.meta.MinTime < s.minTime.PrometheusTimestamp() || b.meta.MinTime > s.maxTime.PrometheusTimestamp() {
return false, nil
}

return true, nil
}

0 comments on commit 6c373cc

Please sign in to comment.