Skip to content

Commit

Permalink
Fix Redis cache error when a query has no chunks to lookup (grafana#2700
Browse files Browse the repository at this point in the history
)

* Fix Redis cache error when a query has no chunks to lookup

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Added CHANGELOG entry

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Fixed another case leading to 'wrong number of arguments for 'mget' command'

Signed-off-by: Marco Pracucci <marco@pracucci.com>
  • Loading branch information
pracucci authored Jun 15, 2020
1 parent 89de65c commit 86d93ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion chunk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ func (c *baseStore) lookupEntriesByQueries(ctx context.Context, queries []IndexQ
log, ctx := spanlogger.New(ctx, "store.lookupEntriesByQueries")
defer log.Span.Finish()

// Nothing to do if there are no queries.
if len(queries) == 0 {
return nil, nil
}

var lock sync.Mutex
var entries []IndexEntry
err := c.index.QueryPages(ctx, queries, func(query IndexQuery, resp ReadBatch) bool {
Expand All @@ -527,7 +532,12 @@ func (c *baseStore) lookupEntriesByQueries(ctx context.Context, queries []IndexQ
return entries, err
}

func (c *baseStore) parseIndexEntries(ctx context.Context, entries []IndexEntry, matcher *labels.Matcher) ([]string, error) {
func (c *baseStore) parseIndexEntries(_ context.Context, entries []IndexEntry, matcher *labels.Matcher) ([]string, error) {
// Nothing to do if there are no entries.
if len(entries) == 0 {
return nil, nil
}

result := make([]string, 0, len(entries))
for _, entry := range entries {
chunkKey, labelValue, _, err := parseChunkTimeRangeValue(entry.RangeValue, entry.Value)
Expand Down
5 changes: 5 additions & 0 deletions composite_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ func (c compositeStore) GetChunkRefs(ctx context.Context, userID string, from, t
return err
}

// Skip it if there are no chunks.
if len(ids) == 0 {
return nil
}

chunkIDs = append(chunkIDs, ids...)
fetchers = append(fetchers, fetcher...)
return nil
Expand Down
5 changes: 5 additions & 0 deletions series_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func (c *seriesStore) GetChunkRefs(ctx context.Context, userID string, from, thr
level.Debug(log).Log("chunks-post-filtering", len(chunks))
chunksPerQuery.Observe(float64(len(chunks)))

// We should return an empty chunks slice if there are no chunks.
if len(chunks) == 0 {
return [][]Chunk{}, []*Fetcher{}, nil
}

return [][]Chunk{chunks}, []*Fetcher{c.baseStore.Fetcher}, nil
}

Expand Down

0 comments on commit 86d93ef

Please sign in to comment.