Browse Source

fix:storage:avoid panic when iterater exhauested (#9945)

Signed-off-by: detailyang <detailyang@gmail.com>
pull/9963/head
detailyang 3 years ago committed by GitHub
parent
commit
3e482c905f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      storage/buffer.go
  2. 1
      storage/buffer_test.go
  3. 2
      storage/memoized_iterator.go
  4. 1
      storage/memoized_iterator_test.go

2
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)

1
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.

2
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

1
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) {

Loading…
Cancel
Save