Skip to content

Commit

Permalink
store: fix error handling in decodePostings
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann committed Aug 24, 2023
1 parent d68c450 commit 3859188
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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
13 changes: 13 additions & 0 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3330,3 +3330,16 @@ 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 3859188

Please sign in to comment.