diff --git a/storage/buffer.go b/storage/buffer.go index 3c7e11b3e..0b38dc077 100644 --- a/storage/buffer.go +++ b/storage/buffer.go @@ -82,7 +82,7 @@ func (b *BufferedSeriesIterator) Seek(t int64) bool { // If the delta would cause us to seek backwards, preserve the buffer // and just continue regular advancement while filling the buffer on the way. - if t0 > b.lastTime { + if b.ok && t0 > b.lastTime { b.buf.reset() b.ok = b.it.Seek(t0) diff --git a/storage/buffer_test.go b/storage/buffer_test.go index 3e0562684..d849ed163 100644 --- a/storage/buffer_test.go +++ b/storage/buffer_test.go @@ -149,6 +149,7 @@ func TestBufferedSeriesIterator(t *testing.T) { bufferEq([]sample{{t: 99, v: 8}, {t: 100, v: 9}}) require.False(t, it.Next(), "next succeeded unexpectedly") + require.False(t, it.Seek(1024), "seek succeeded unexpectedly") } // At() should not be called once Next() returns false. diff --git a/storage/memoized_iterator.go b/storage/memoized_iterator.go index 3538c7f48..d72338b78 100644 --- a/storage/memoized_iterator.go +++ b/storage/memoized_iterator.go @@ -71,7 +71,7 @@ func (b *MemoizedSeriesIterator) PeekPrev() (t int64, v float64, ok bool) { func (b *MemoizedSeriesIterator) Seek(t int64) bool { t0 := t - b.delta - if t0 > b.lastTime { + if b.ok && t0 > b.lastTime { // Reset the previously stored element because the seek advanced // more than the delta. b.prevTime = math.MinInt64 diff --git a/storage/memoized_iterator_test.go b/storage/memoized_iterator_test.go index ef773ee0f..f606f2fae 100644 --- a/storage/memoized_iterator_test.go +++ b/storage/memoized_iterator_test.go @@ -68,6 +68,7 @@ func TestMemoizedSeriesIterator(t *testing.T) { prevSampleEq(100, 9, true) require.False(t, it.Next(), "next succeeded unexpectedly") + require.False(t, it.Seek(1024), "seek succeeded unexpectedly") } func BenchmarkMemoizedSeriesIterator(b *testing.B) {