Merge pull request #97 from Gouthamve/nit
Fix bug with Seek() and optimise bounding params.
This commit is contained in:
commit
a2948f3c5f
18
querier.go
18
querier.go
|
@ -661,10 +661,6 @@ func newChunkSeriesIterator(cs []*ChunkMeta, dranges intervals, mint, maxt int64
|
|||
}
|
||||
}
|
||||
|
||||
func (it *chunkSeriesIterator) inBounds(t int64) bool {
|
||||
return t >= it.mint && t <= it.maxt
|
||||
}
|
||||
|
||||
func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
||||
if t > it.maxt {
|
||||
return false
|
||||
|
@ -677,7 +673,9 @@ func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
|||
|
||||
// Only do binary search forward to stay in line with other iterators
|
||||
// that can only move forward.
|
||||
x := sort.Search(len(it.chunks[it.i:]), func(i int) bool { return it.chunks[i].MinTime >= t })
|
||||
x := sort.Search(len(it.chunks[it.i:]), func(i int) bool {
|
||||
return it.chunks[it.i+i].MinTime >= t
|
||||
})
|
||||
x += it.i
|
||||
|
||||
// If the timestamp was not found, it might be in the last chunk.
|
||||
|
@ -712,9 +710,15 @@ func (it *chunkSeriesIterator) At() (t int64, v float64) {
|
|||
func (it *chunkSeriesIterator) Next() bool {
|
||||
for it.cur.Next() {
|
||||
t, _ := it.cur.At()
|
||||
if it.inBounds(t) {
|
||||
return true
|
||||
if t < it.mint {
|
||||
return it.Seek(it.mint)
|
||||
}
|
||||
|
||||
if t > it.maxt {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if err := it.cur.Err(); err != nil {
|
||||
|
|
|
@ -1027,6 +1027,22 @@ func TestSeriesIterator(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
// Regression for: https://github.com/prometheus/tsdb/pull/97
|
||||
func TestCSIteratorDoubleSeek(t *testing.T) {
|
||||
chkMetas := []*ChunkMeta{
|
||||
chunkFromSamples([]sample{}),
|
||||
chunkFromSamples([]sample{{1, 1}, {2, 2}, {3, 3}}),
|
||||
chunkFromSamples([]sample{{4, 4}, {5, 5}}),
|
||||
}
|
||||
|
||||
res := newChunkSeriesIterator(chkMetas, nil, 2, 8)
|
||||
require.True(t, res.Seek(1))
|
||||
require.True(t, res.Seek(2))
|
||||
ts, v := res.At()
|
||||
require.Equal(t, int64(2), ts)
|
||||
require.Equal(t, float64(2), v)
|
||||
}
|
||||
|
||||
func TestPopulatedCSReturnsValidChunkSlice(t *testing.T) {
|
||||
lbls := []labels.Labels{labels.New(labels.Label{"a", "b"})}
|
||||
chunkMetas := [][]*ChunkMeta{
|
||||
|
|
Loading…
Reference in New Issue