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 08a856b1e9
commit 3e482c905f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -82,7 +82,7 @@ func (b *BufferedSeriesIterator) Seek(t int64) bool {
// If the delta would cause us to seek backwards, preserve the buffer // If the delta would cause us to seek backwards, preserve the buffer
// and just continue regular advancement while filling the buffer on the way. // 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.buf.reset()
b.ok = b.it.Seek(t0) b.ok = b.it.Seek(t0)

@ -149,6 +149,7 @@ func TestBufferedSeriesIterator(t *testing.T) {
bufferEq([]sample{{t: 99, v: 8}, {t: 100, v: 9}}) bufferEq([]sample{{t: 99, v: 8}, {t: 100, v: 9}})
require.False(t, it.Next(), "next succeeded unexpectedly") 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. // At() should not be called once Next() returns false.

@ -71,7 +71,7 @@ func (b *MemoizedSeriesIterator) PeekPrev() (t int64, v float64, ok bool) {
func (b *MemoizedSeriesIterator) Seek(t int64) bool { func (b *MemoizedSeriesIterator) Seek(t int64) bool {
t0 := t - b.delta t0 := t - b.delta
if t0 > b.lastTime { if b.ok && t0 > b.lastTime {
// Reset the previously stored element because the seek advanced // Reset the previously stored element because the seek advanced
// more than the delta. // more than the delta.
b.prevTime = math.MinInt64 b.prevTime = math.MinInt64

@ -68,6 +68,7 @@ func TestMemoizedSeriesIterator(t *testing.T) {
prevSampleEq(100, 9, true) prevSampleEq(100, 9, true)
require.False(t, it.Next(), "next succeeded unexpectedly") require.False(t, it.Next(), "next succeeded unexpectedly")
require.False(t, it.Seek(1024), "seek succeeded unexpectedly")
} }
func BenchmarkMemoizedSeriesIterator(b *testing.B) { func BenchmarkMemoizedSeriesIterator(b *testing.B) {

Loading…
Cancel
Save