From 6c373cc84d28c5cac0744b861e488cb5056643a4 Mon Sep 17 00:00:00 2001
From: Povilas Versockas
Date: Thu, 25 Apr 2019 08:11:06 +0300
Subject: [PATCH] Skip loading cache for unneeded blocks
---
pkg/store/bucket.go | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go
index 4a5c0af21c0..1058ed808ca 100644
--- a/pkg/store/bucket.go
+++ b/pkg/store/bucket.go
@@ -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 {
@@ -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()
@@ -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
+}