Skip to content

Commit

Permalink
Check for error when calling Next(). Also add the start of a test to …
Browse files Browse the repository at this point in the history
…ensure encode/decode works fine
  • Loading branch information
paul1r committed Jan 10, 2024
1 parent e9d2d98 commit ecc2aed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/storage/bloom/v1/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package v1

import (
"fmt"
"github.com/go-kit/kit/log/level"
util_log "github.com/grafana/loki/pkg/util/log"

"github.com/pkg/errors"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -109,7 +111,9 @@ func (bq *BlockQuerier) Next() bool {
series := bq.series.At()

bq.blooms.Seek(series.Offset)
if !bq.blooms.Next() {
if bq.blooms.Err() != nil || !bq.blooms.Next() {

level.Info(util_log.Logger).Log("msg", "error seeking to series offset", "offset", series.Offset, "err", bq.blooms.Err())
return false
}

Expand Down Expand Up @@ -154,7 +158,7 @@ func (bq *BlockQuerier) CheckChunksForSeries(fp model.Fingerprint, chks ChunkRef
}

bq.blooms.Seek(series.Offset)
if !bq.blooms.Next() {
if bq.blooms.Err() != nil || !bq.blooms.Next() {
return chks, fmt.Errorf("seeking to bloom for fp: %v", fp)
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/storage/bloom/v1/bloom_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v1

import (
"github.com/grafana/loki/pkg/util/encoding"
"testing"
)

func TestEncodeDecode(t *testing.T) {
numSeries := 100
numKeysPerSeries := 10000
data, _ := mkBasicSeriesWithBlooms(numSeries, numKeysPerSeries, 0, 0xffff, 0, 10000)
enc := &encoding.Encbuf{}
data[0].Bloom.Encode(enc)
dec := encoding.DecWith(enc.Get())
var bloom Bloom
bloom.Decode(&dec)

}

0 comments on commit ecc2aed

Please sign in to comment.