From a51b2666d746738092b20196a79c02b8dc0c83ac Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Wed, 5 Apr 2017 23:59:10 +0530 Subject: [PATCH] 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 --- head.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/head.go b/head.go index 3a98b7a4e..93584c9cd 100644 --- a/head.go +++ b/head.go @@ -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 {