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 { switch e {
case EncXOR: case EncXOR:
return &XORChunk{ return &XORChunk{
b: &bstream{count: 8}, b: &bstream{count: 0, stream: d},
num: binary.BigEndian.Uint16(d), num: binary.BigEndian.Uint16(d),
}, nil }, nil
} }

View file

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