Mutating the chunks can change their length. Hence referencing using
previous indices can cause panics.

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-05-01 14:33:56 +05:30
parent 6178de9acc
commit 6169c33fb8
No known key found for this signature in database
GPG key ID: F1C217E8E9023CAD
2 changed files with 57 additions and 2 deletions

View file

@ -400,13 +400,14 @@ func (s *populatedChunkSeries) Next() bool {
for s.set.Next() {
lset, chks := s.set.At()
from := 0
for i, c := range chks {
if c.MaxTime < s.mint {
chks = chks[1:]
from = i
continue
}
if c.MinTime > s.maxt {
chks = chks[:i]
chks = chks[from+1 : i]
break
}
c.Chunk, s.err = s.chunks.Chunk(c.Ref)

View file

@ -838,3 +838,57 @@ func TestSeriesIterator(t *testing.T) {
return
}
func TestPopulatedCSReturnsValidChunkSlice(t *testing.T) {
lbls := []labels.Labels{labels.New(labels.Label{"a", "b"})}
chunkMetas := [][]*ChunkMeta{
{
{MinTime: 1, MaxTime: 2, Ref: 1},
{MinTime: 3, MaxTime: 4, Ref: 2},
{MinTime: 10, MaxTime: 12, Ref: 3},
},
}
cr := mockChunkReader(
map[uint64]chunks.Chunk{
1: chunks.NewXORChunk(),
2: chunks.NewXORChunk(),
3: chunks.NewXORChunk(),
},
)
m := &mockChunkSeriesSet{l: lbls, cm: chunkMetas, i: -1}
p := &populatedChunkSeries{
set: m,
chunks: cr,
mint: 6,
maxt: 9,
}
require.False(t, p.Next())
return
}
type mockChunkSeriesSet struct {
l []labels.Labels
cm [][]*ChunkMeta
i int
}
func (m *mockChunkSeriesSet) Next() bool {
if len(m.l) != len(m.cm) {
return false
}
m.i++
return m.i < len(m.l)
}
func (m *mockChunkSeriesSet) At() (labels.Labels, []*ChunkMeta) {
return m.l[m.i], m.cm[m.i]
}
func (m *mockChunkSeriesSet) Err() error {
return nil
}