diff --git a/db.go b/db.go index 010a5968d..74dc66e0f 100644 --- a/db.go +++ b/db.go @@ -538,17 +538,17 @@ type chunkDesc struct { chunk chunks.Chunk // Caching fields. - firsTimestamp int64 - lastTimestamp int64 - lastValue float64 - numSamples int + firstTimestamp int64 + lastTimestamp int64 + lastValue float64 + numSamples int app chunks.Appender // Current appender for the chunks. } func (cd *chunkDesc) append(ts int64, v float64) { if cd.numSamples == 0 { - cd.firsTimestamp = ts + cd.firstTimestamp = ts } cd.app.Append(ts, v) diff --git a/head.go b/head.go index aee02f69f..4cdf38bd6 100644 --- a/head.go +++ b/head.go @@ -2,6 +2,7 @@ package tsdb import ( "errors" + "math" "sort" "sync" @@ -122,7 +123,7 @@ func (h *HeadBlock) Series(ref uint32) (labels.Labels, []ChunkMeta, error) { cd := h.descs[ref] meta := ChunkMeta{ - MinTime: cd.firsTimestamp, + MinTime: cd.firstTimestamp, MaxTime: cd.lastTimestamp, Ref: ref, } @@ -155,9 +156,11 @@ func (h *HeadBlock) create(hash uint64, lset labels.Labels) *chunkDesc { var err error cd := &chunkDesc{ - lset: lset, - chunk: chunks.NewXORChunk(), + lset: lset, + chunk: chunks.NewXORChunk(), + lastTimestamp: math.MinInt64, } + cd.app, err = cd.chunk.Appender() if err != nil { // Getting an Appender for a new chunk must not panic. @@ -276,7 +279,7 @@ func (h *HeadBlock) persist(indexw IndexWriter, chunkw SeriesWriter) error { for ref, cd := range h.descs { if err := chunkw.WriteSeries(uint32(ref), cd.lset, []ChunkMeta{ { - MinTime: cd.firsTimestamp, + MinTime: cd.firstTimestamp, MaxTime: cd.lastTimestamp, Chunk: cd.chunk, },