Merge pull request #10030 from prometheus/beorn7/iterators
storage: expose and fix bug #10027 in iterators' Seek method
This commit is contained in:
commit
565ee356df
|
@ -360,6 +360,9 @@ func (c *concreteSeriesIterator) Seek(t int64) bool {
|
|||
if c.cur == -1 {
|
||||
c.cur = 0
|
||||
}
|
||||
if c.cur >= len(c.series.samples) {
|
||||
return false
|
||||
}
|
||||
// No-op check.
|
||||
if s := c.series.samples[c.cur]; s.Timestamp >= t {
|
||||
return true
|
||||
|
|
|
@ -233,6 +233,11 @@ func TestConcreteSeriesIterator(t *testing.T) {
|
|||
ts, v = it.At()
|
||||
require.Equal(t, int64(3), ts)
|
||||
require.Equal(t, 3., v)
|
||||
|
||||
// Seek beyond the end.
|
||||
require.False(t, it.Seek(5))
|
||||
// And we don't go back. (This exposes issue #10027.)
|
||||
require.False(t, it.Seek(2))
|
||||
}
|
||||
|
||||
func TestFromQueryResultWithDuplicates(t *testing.T) {
|
||||
|
|
|
@ -99,6 +99,9 @@ func (it *listSeriesIterator) Seek(t int64) bool {
|
|||
if it.idx == -1 {
|
||||
it.idx = 0
|
||||
}
|
||||
if it.idx >= it.samples.Len() {
|
||||
return false
|
||||
}
|
||||
// No-op check.
|
||||
if s := it.samples.Get(it.idx); s.T() >= t {
|
||||
return true
|
||||
|
|
|
@ -51,4 +51,9 @@ func TestListSeriesIterator(t *testing.T) {
|
|||
ts, v = it.At()
|
||||
require.Equal(t, int64(3), ts)
|
||||
require.Equal(t, 3., v)
|
||||
|
||||
// Seek beyond the end.
|
||||
require.False(t, it.Seek(5))
|
||||
// And we don't go back. (This exposes issue #10027.)
|
||||
require.False(t, it.Seek(2))
|
||||
}
|
||||
|
|
|
@ -159,6 +159,9 @@ func (it *listSeriesIterator) Seek(t int64) bool {
|
|||
if it.idx == -1 {
|
||||
it.idx = 0
|
||||
}
|
||||
if it.idx >= len(it.list) {
|
||||
return false
|
||||
}
|
||||
// No-op check.
|
||||
if s := it.list[it.idx]; s.T() >= t {
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue