Fix AllPostings added twice (#13893)
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

* handle all postings added twice

---------

Signed-off-by: Ben Ye <benye@amazon.com>
This commit is contained in:
Ben Ye 2024-11-10 09:17:21 -08:00 committed by GitHub
parent 76432aaf4e
commit f9057544cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -193,6 +193,11 @@ func selectChunkSeriesSet(ctx context.Context, sortSeries bool, hints *storage.S
// PostingsForMatchers assembles a single postings iterator against the index reader // PostingsForMatchers assembles a single postings iterator against the index reader
// based on the given matchers. The resulting postings are not ordered by series. // based on the given matchers. The resulting postings are not ordered by series.
func PostingsForMatchers(ctx context.Context, ix IndexReader, ms ...*labels.Matcher) (index.Postings, error) { func PostingsForMatchers(ctx context.Context, ix IndexReader, ms ...*labels.Matcher) (index.Postings, error) {
if len(ms) == 1 && ms[0].Name == "" && ms[0].Value == "" {
k, v := index.AllPostingsKey()
return ix.Postings(ctx, k, v)
}
var its, notIts []index.Postings var its, notIts []index.Postings
// See which label must be non-empty. // See which label must be non-empty.
// Optimization for case like {l=~".", l!="1"}. // Optimization for case like {l=~".", l!="1"}.
@ -247,13 +252,10 @@ func PostingsForMatchers(ctx context.Context, ix IndexReader, ms ...*labels.Matc
return nil, ctx.Err() return nil, ctx.Err()
} }
switch { switch {
case m.Name == "" && m.Value == "": // Special-case for AllPostings, used in tests at least. case m.Name == "" && m.Value == "":
k, v := index.AllPostingsKey() // We already handled the case at the top of the function,
allPostings, err := ix.Postings(ctx, k, v) // and it is unexpected to get all postings again here.
if err != nil { return nil, errors.New("unexpected all postings")
return nil, err
}
its = append(its, allPostings)
case m.Type == labels.MatchRegexp && m.Value == ".*": case m.Type == labels.MatchRegexp && m.Value == ".*":
// .* regexp matches any string: do nothing. // .* regexp matches any string: do nothing.
case m.Type == labels.MatchNotRegexp && m.Value == ".*": case m.Type == labels.MatchNotRegexp && m.Value == ".*":