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

Signed-off-by: detailyang <detailyang@gmail.com>
This commit is contained in:
detailyang 2021-12-07 22:20:00 +08:00 committed by GitHub
parent 08a856b1e9
commit 3e482c905f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 2 deletions

View file

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

View file

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

View file

@ -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

View file

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