Skip to content

Commit b01ef46

Browse files
committed
Fix FindAtOrAfter where seek position is between two smallchunks
and add a test that covers that case. Signed-off-by: Bryan Boreham <[email protected]>
1 parent 5a44db6 commit b01ef46

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/chunk/encoding/bigchunk.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ func (it *bigchunkIterator) FindAtOrAfter(target model.Time) bool {
261261
return true
262262
}
263263
}
264+
// Timestamp is after the end of that chunk - if there is another chunk
265+
// then the position we need is at the beginning of it.
266+
if it.i+1 < len(it.chunks) {
267+
it.i++
268+
it.curr = it.chunks[it.i].Iterator()
269+
it.curr.Next()
270+
return true
271+
}
264272
return false
265273
}
266274

pkg/chunk/encoding/chunk_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ func testChunkSeek(t *testing.T, encoding Encoding, samples int) {
147147

148148
iter := chunk.NewIterator()
149149
for i := 0; i < samples; i += samples / 10 {
150+
if i > 0 {
151+
// Seek one millisecond before the actual time
152+
require.True(t, iter.FindAtOrAfter(model.Time(i*step-1)), "1ms before step %d not found", i)
153+
sample := iter.Value()
154+
require.EqualValues(t, model.Time(i*step), sample.Timestamp)
155+
require.EqualValues(t, model.SampleValue(i), sample.Value)
156+
}
157+
// Now seek to exactly the right time
150158
require.True(t, iter.FindAtOrAfter(model.Time(i*step)))
151159
sample := iter.Value()
152160
require.EqualValues(t, model.Time(i*step), sample.Timestamp)

0 commit comments

Comments
 (0)