Skip to content

Commit

Permalink
fix lazy expanded postings cache and bug of non equal matcher with no…
Browse files Browse the repository at this point in the history
…n existent values

Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Mar 21, 2024
1 parent 4a2a455 commit ee6653d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,13 +1196,10 @@ OUTER:
if err := b.ctx.Err(); err != nil {
return err
}
ok, err := b.indexr.LoadSeriesForTime(postingsBatch[i], &b.symbolizedLset, &b.chkMetas, b.skipChunks, b.mint, b.maxt)
hasMatchedChunks, err := b.indexr.LoadSeriesForTime(postingsBatch[i], &b.symbolizedLset, &b.chkMetas, b.skipChunks, b.mint, b.maxt)
if err != nil {
return errors.Wrap(err, "read series")
}
if !ok {
continue
}

if err := b.indexr.LookupLabelsSymbols(b.ctx, b.symbolizedLset, b.b); err != nil {
return errors.Wrap(err, "Lookup labels symbols")
Expand All @@ -1221,6 +1218,11 @@ OUTER:
if b.lazyPostings.lazyExpanded() {
b.expandedPostings = append(b.expandedPostings, postingsBatch[i])
}
// Even though there is no chunks found in the requested time range, we need to continue
// for loop after checking lazy posting matchers because of the expanded postings cache.
if !hasMatchedChunks {
continue
}

completeLabelset := labelpb.ExtendSortedLabels(b.lset, b.extLset)
if b.extLsetToRemove != nil {
Expand Down
9 changes: 7 additions & 2 deletions pkg/store/lazy_postings.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ func optimizePostingsFetchByDownloadedBytes(r *bucketIndexReader, postingGroups
return nil, false, errors.Wrapf(err, "postings offsets for %s", pg.name)
}

// No posting ranges found means empty posting.
if len(rngs) == 0 {
// If the posting group adds keys, no posting ranges found means empty posting.
if len(pg.addKeys) > 0 && len(rngs) == 0 {
return nil, true, nil
}
// If the posting group removes keys, no posting ranges found is fine. It means
// that the posting group is a noop. {job != "some_non_existent_value"}
if len(pg.removeKeys) > 0 && len(rngs) == 0 {
continue
}
for _, r := range rngs {
if r == indexheader.NotFoundRange {
continue
Expand Down

0 comments on commit ee6653d

Please sign in to comment.