Fix Panic When Accessing Uncut memorySeries

When calling AddFast, we check the details of the head chunk of the
referred memorySeries. But it could happen that there are no chunks in
the series at all.

Currently, we are deferring chunk creation to when we actually append
samples, but we can be sure that there will be samples if the series is
created. We will be consuming no extra memory by cutting a chunk when we
create the series.

Ref: #28 comment 2

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-04-05 23:59:10 +05:30
parent 1579e12011
commit a51b2666d7
1 changed files with 3 additions and 1 deletions

View File

@ -565,6 +565,8 @@ func (h *headBlock) create(hash uint64, lset labels.Labels) *memSeries {
lset: lset,
ref: uint32(len(h.series)),
}
// create the initial chunk and appender
s.cut()
// Allocate empty space until we can insert at the given index.
h.series = append(h.series, s)
@ -627,7 +629,7 @@ func (s *memSeries) append(t int64, v float64) bool {
var c *memChunk
if s.app == nil || s.head().samples > 2000 {
if s.head().samples > 2000 {
c = s.cut()
c.minTime = t
} else {