Fix bug with Seek() and optimise bounding params.

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-06-13 11:24:04 +05:30
parent d4cb579443
commit 9e1f34dae3
No known key found for this signature in database
GPG Key ID: F1C217E8E9023CAD
1 changed files with 11 additions and 7 deletions

View File

@ -657,10 +657,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) { func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
if t > it.maxt { if t > it.maxt {
return false return false
@ -673,7 +669,9 @@ func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
// Only do binary search forward to stay in line with other iterators // Only do binary search forward to stay in line with other iterators
// that can only move forward. // 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 x += it.i
// If the timestamp was not found, it might be in the last chunk. // If the timestamp was not found, it might be in the last chunk.
@ -708,9 +706,15 @@ func (it *chunkSeriesIterator) At() (t int64, v float64) {
func (it *chunkSeriesIterator) Next() bool { func (it *chunkSeriesIterator) Next() bool {
for it.cur.Next() { for it.cur.Next() {
t, _ := it.cur.At() t, _ := it.cur.At()
if it.inBounds(t) { if t < it.mint {
return true return it.Seek(it.mint)
} }
if t > it.maxt {
return false
}
return true
} }
if err := it.cur.Err(); err != nil { if err := it.cur.Err(); err != nil {