diff --git a/pkg/storegateway/batch_series.go b/pkg/storegateway/batch_series.go index 72b78a5051c..e36bd7ebede 100644 --- a/pkg/storegateway/batch_series.go +++ b/pkg/storegateway/batch_series.go @@ -10,7 +10,6 @@ import ( "github.com/oklog/ulid" "github.com/pkg/errors" "github.com/prometheus/prometheus/model/labels" - "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/tsdb/hashcache" "golang.org/x/sync/errgroup" @@ -20,36 +19,6 @@ import ( "github.com/grafana/mimir/pkg/util/pool" ) -type seriesHasher interface { - Hash(seriesID storage.SeriesRef, lset labels.Labels, stats *queryStats) uint64 -} - -type cachedSeriesHasher struct { - cache *hashcache.BlockSeriesHashCache -} - -func (b cachedSeriesHasher) Hash(id storage.SeriesRef, lset labels.Labels, stats *queryStats) uint64 { - stats.seriesHashCacheRequests++ - - hash, ok := b.cache.Fetch(id) - if !ok { - hash = lset.Hash() - b.cache.Store(id, hash) - } else { - stats.seriesHashCacheHits++ - } - return hash -} - -func shardOwned(shard *sharding.ShardSelector, hasher seriesHasher, id storage.SeriesRef, lset labels.Labels, stats *queryStats) bool { - if shard == nil { - return true - } - hash := hasher.Hash(id, lset, stats) - - return hash%shard.ShardCount == shard.ShardIndex -} - func (s *BucketStore) batchSetsForBlocks(ctx context.Context, req *storepb.SeriesRequest, blocks []*bucketBlock, indexReaders map[ulid.ULID]*bucketIndexReader, chunkReaders *chunkReaders, chunksPool pool.Bytes, shardSelector *sharding.ShardSelector, matchers []*labels.Matcher, chunksLimiter ChunksLimiter, seriesLimiter SeriesLimiter, stats *safeQueryStats) (storepb.SeriesSet, *hintspb.SeriesResponseHints, func(), error) { resHints := &hintspb.SeriesResponseHints{} mtx := sync.Mutex{} diff --git a/pkg/storegateway/series_refs.go b/pkg/storegateway/series_refs.go index c7692148de0..8034f8d1b25 100644 --- a/pkg/storegateway/series_refs.go +++ b/pkg/storegateway/series_refs.go @@ -700,6 +700,36 @@ func metasToChunks(blockID ulid.ULID, metas []chunks.Meta) []seriesChunkRef { return chks } +type seriesHasher interface { + Hash(seriesID storage.SeriesRef, lset labels.Labels, stats *queryStats) uint64 +} + +type cachedSeriesHasher struct { + cache *hashcache.BlockSeriesHashCache +} + +func (b cachedSeriesHasher) Hash(id storage.SeriesRef, lset labels.Labels, stats *queryStats) uint64 { + stats.seriesHashCacheRequests++ + + hash, ok := b.cache.Fetch(id) + if !ok { + hash = lset.Hash() + b.cache.Store(id, hash) + } else { + stats.seriesHashCacheHits++ + } + return hash +} + +func shardOwned(shard *sharding.ShardSelector, hasher seriesHasher, id storage.SeriesRef, lset labels.Labels, stats *queryStats) bool { + if shard == nil { + return true + } + hash := hasher.Hash(id, lset, stats) + + return hash%shard.ShardCount == shard.ShardIndex +} + type postingsSetsIterator struct { postings []storage.SeriesRef