Reda correct label number, fix buffered iterator panic

This commit is contained in:
Fabian Reinartz 2016-12-20 14:21:50 +01:00
parent d9ca4b47f5
commit ce7f4106c2
3 changed files with 15 additions and 10 deletions

View file

@ -44,7 +44,7 @@ func FromData(e Encoding, d []byte) (Chunk, error) {
switch e {
case EncXOR:
return &XORChunk{
b: &bstream{count: 8},
b: &bstream{count: 0, stream: d},
num: binary.BigEndian.Uint16(d),
}, nil
}

View file

@ -2,6 +2,7 @@ package tsdb
import (
"fmt"
"math"
"sort"
"strings"
@ -657,14 +658,17 @@ func (it *chunkSeriesIterator) Err() error {
type BufferedSeriesIterator struct {
it SeriesIterator
buf *sampleRing
lastTime int64
}
// NewBuffer returns a new iterator that buffers the values within the time range
// of the current element and the duration of delta before.
func NewBuffer(it SeriesIterator, delta int64) *BufferedSeriesIterator {
return &BufferedSeriesIterator{
it: it,
buf: newSampleRing(delta, 16),
it: it,
buf: newSampleRing(delta, 16),
lastTime: math.MinInt64,
}
}
@ -676,14 +680,13 @@ func (b *BufferedSeriesIterator) PeekBack() (t int64, v float64, ok bool) {
// Seek advances the iterator to the element at time t or greater.
func (b *BufferedSeriesIterator) Seek(t int64) bool {
tcur, _ := b.it.Values()
t0 := t - b.buf.delta
// If the delta would cause us to seek backwards, preserve the buffer
// and just continue regular advancment while filling the buffer on the way.
if t0 <= tcur {
if t0 <= b.lastTime {
for b.Next() {
if tcur, _ = b.it.Values(); tcur >= t {
if tcur, _ := b.it.Values(); tcur >= t {
return true
}
}
@ -711,7 +714,9 @@ func (b *BufferedSeriesIterator) Next() bool {
// Add current element to buffer before advancing.
b.buf.add(b.it.Values())
return b.it.Next()
ok := b.it.Next()
b.lastTime, _ = b.Values()
return ok
}
// Values returns the current element of the iterator.

View file

@ -247,9 +247,9 @@ func (r *indexReader) Series(ref uint32, mint, maxt int64) (Series, error) {
}
b := r.b[int(ref)+n:]
offsets := make([]uint32, 0, k)
offsets := make([]uint32, 0, 2*k)
for i := 0; i < int(k); i++ {
for i := 0; i < 2*int(k); i++ {
o, n := binary.Uvarint(b)
if n < 1 {
return nil, errors.Wrap(errInvalidSize, "symbol offset")