Skip to content

Commit

Permalink
store: fix error handling in decodePostings (#6650)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann authored Aug 24, 2023
1 parent d68c450 commit 26b48a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#6650](https://github.com/thanos-io/thanos/pull/6650) Store: fix error handling in decodePostings

### Added

- [#6605](https://github.com/thanos-io/thanos/pull/6605) Query Frontend: Support vertical sharding binary expression with metric name when no matching labels specified.
Expand Down
5 changes: 2 additions & 3 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2864,14 +2864,13 @@ func (r *bucketIndexReader) decodeCachedPostings(b []byte) (index.Postings, []fu
)
if isDiffVarintSnappyEncodedPostings(b) || isDiffVarintSnappyStreamedEncodedPostings(b) {
s := time.Now()
clPostings, err := decodePostings(b)
l, err = decodePostings(b)
r.stats.cachedPostingsDecompressions += 1
r.stats.CachedPostingsDecompressionTimeSum += time.Since(s)
if err != nil {
r.stats.cachedPostingsDecompressionErrors += 1
} else {
closeFns = append(closeFns, clPostings.close)
l = clPostings
closeFns = append(closeFns, l.(closeablePostings).close)
}
} else {
_, l, err = r.dec.Postings(b)
Expand Down
12 changes: 12 additions & 0 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3330,3 +3330,15 @@ func TestExpandedPostingsRace(t *testing.T) {
wg.Wait()
}
}

func TestBucketIndexReader_decodeCachedPostingsErrors(t *testing.T) {
bir := bucketIndexReader{stats: &queryStats{}}
t.Run("should return error on broken cached postings without snappy prefix", func(t *testing.T) {
_, _, err := bir.decodeCachedPostings([]byte("foo"))
testutil.NotOk(t, err)
})
t.Run("should return error on broken cached postings with snappy prefix", func(t *testing.T) {
_, _, err := bir.decodeCachedPostings(append([]byte(codecHeaderSnappy), []byte("foo")...))
testutil.NotOk(t, err)
})
}

0 comments on commit 26b48a5

Please sign in to comment.