From a04be0bc1c85eb2d6774198c37418020115c60d4 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 19 Sep 2017 14:24:26 +0200 Subject: [PATCH] vendor: update prometheus/tsdb --- vendor/github.com/prometheus/tsdb/block.go | 5 --- vendor/github.com/prometheus/tsdb/db.go | 3 +- vendor/github.com/prometheus/tsdb/head.go | 46 ++++++++++++++-------- vendor/github.com/prometheus/tsdb/index.go | 3 ++ vendor/github.com/prometheus/tsdb/wal.go | 15 ++++--- vendor/vendor.json | 14 +++---- 6 files changed, 49 insertions(+), 37 deletions(-) diff --git a/vendor/github.com/prometheus/tsdb/block.go b/vendor/github.com/prometheus/tsdb/block.go index 67cd57491..232e64e67 100644 --- a/vendor/github.com/prometheus/tsdb/block.go +++ b/vendor/github.com/prometheus/tsdb/block.go @@ -64,11 +64,6 @@ type Appendable interface { Appender() Appender } -// Queryable defines an entity which provides a Querier. -type Queryable interface { - Querier(mint, maxt int64) Querier -} - // BlockMeta provides meta information about a block. type BlockMeta struct { // Unique identifier for the block and its contents. Changes on compaction. diff --git a/vendor/github.com/prometheus/tsdb/db.go b/vendor/github.com/prometheus/tsdb/db.go index c9745cfc6..87b5ed253 100644 --- a/vendor/github.com/prometheus/tsdb/db.go +++ b/vendor/github.com/prometheus/tsdb/db.go @@ -165,8 +165,7 @@ func Open(dir string, l log.Logger, r prometheus.Registerer, opts *Options) (db return nil, err } if l == nil { - l = log.NewLogfmtLogger(os.Stdout) - l = log.With(l, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) + l = log.NewNopLogger() } if opts == nil { opts = DefaultOptions diff --git a/vendor/github.com/prometheus/tsdb/head.go b/vendor/github.com/prometheus/tsdb/head.go index ea7b63f8a..a5ce94e45 100644 --- a/vendor/github.com/prometheus/tsdb/head.go +++ b/vendor/github.com/prometheus/tsdb/head.go @@ -185,13 +185,18 @@ func NewHead(r prometheus.Registerer, l log.Logger, wal WAL, chunkRange int64) ( return h, nil } +// ReadWAL initializes the head by consuming the write ahead log. func (h *Head) ReadWAL() error { r := h.wal.Reader() mint := h.MinTime() seriesFunc := func(series []RefSeries) error { for _, s := range series { - h.create(s.Labels.Hash(), s.Labels) + h.getOrCreateWithID(s.Ref, s.Labels.Hash(), s.Labels) + + if h.lastSeriesID < s.Ref { + h.lastSeriesID = s.Ref + } } return nil } @@ -202,7 +207,8 @@ func (h *Head) ReadWAL() error { } ms := h.series.getByID(s.Ref) if ms == nil { - return errors.Errorf("unknown series reference %d; abort WAL restore", s.Ref) + h.logger.Log("msg", "unknown series reference in WAL", "ref", s.Ref) + continue } _, chunkCreated := ms.append(s.T, s.V) if chunkCreated { @@ -210,7 +216,6 @@ func (h *Head) ReadWAL() error { h.metrics.chunks.Inc() } } - return nil } deletesFunc := func(stones []Stone) error { @@ -222,7 +227,6 @@ func (h *Head) ReadWAL() error { h.tombstones.add(s.ref, itv) } } - return nil } @@ -379,17 +383,12 @@ func (a *headAppender) Add(lset labels.Labels, t int64, v float64) (uint64, erro if t < a.mint { return 0, ErrOutOfBounds } - hash := lset.Hash() - - s := a.head.series.getByHash(hash, lset) - - if s == nil { - s = a.head.create(hash, lset) + s, created := a.head.getOrCreate(lset.Hash(), lset) + if created { a.series = append(a.series, RefSeries{ Ref: s.ref, Labels: lset, - hash: hash, }) } return s.ref, a.AddFast(s.ref, t, v) @@ -839,20 +838,32 @@ func (h *headIndexReader) LabelIndices() ([][]string, error) { return res, nil } -func (h *Head) create(hash uint64, lset labels.Labels) *memSeries { - h.metrics.series.Inc() - h.metrics.seriesCreated.Inc() +func (h *Head) getOrCreate(hash uint64, lset labels.Labels) (*memSeries, bool) { + // Just using `getOrSet` below would be semantically sufficient, but we'd create + // a new series on every sample inserted via Add(), which causes allocations + // and makes our series IDs rather random and harder to compress in postings. + s := h.series.getByHash(hash, lset) + if s != nil { + return s, false + } // Optimistically assume that we are the first one to create the series. id := atomic.AddUint64(&h.lastSeriesID, 1) + + return h.getOrCreateWithID(id, hash, lset) +} + +func (h *Head) getOrCreateWithID(id, hash uint64, lset labels.Labels) (*memSeries, bool) { s := newMemSeries(lset, id, h.chunkRange) s, created := h.series.getOrSet(hash, s) - // Skip indexing if we didn't actually create the series. if !created { - return s + return s, false } + h.metrics.series.Inc() + h.metrics.seriesCreated.Inc() + h.postings.add(id, lset) h.symMtx.Lock() @@ -870,7 +881,7 @@ func (h *Head) create(hash uint64, lset labels.Labels) *memSeries { h.symbols[l.Value] = struct{}{} } - return s + return s, true } // seriesHashmap is a simple hashmap for memSeries by their label set. It is built @@ -1023,6 +1034,7 @@ func (s *stripeSeries) getOrSet(hash uint64, series *memSeries) (*memSeries, boo s.locks[i].Lock() if prev := s.hashes[i].get(hash, series.lset); prev != nil { + s.locks[i].Unlock() return prev, false } s.hashes[i].set(hash, series) diff --git a/vendor/github.com/prometheus/tsdb/index.go b/vendor/github.com/prometheus/tsdb/index.go index fd9b25162..3cdaad74d 100644 --- a/vendor/github.com/prometheus/tsdb/index.go +++ b/vendor/github.com/prometheus/tsdb/index.go @@ -570,6 +570,9 @@ var ( errInvalidFlag = fmt.Errorf("invalid flag") ) +// NewIndexReader returns a new IndexReader on the given directory. +func NewIndexReader(dir string) (IndexReader, error) { return newIndexReader(dir) } + // newIndexReader returns a new indexReader on the given directory. func newIndexReader(dir string) (*indexReader, error) { f, err := openMmapFile(filepath.Join(dir, "index")) diff --git a/vendor/github.com/prometheus/tsdb/wal.go b/vendor/github.com/prometheus/tsdb/wal.go index 9af9a1853..27984ea0c 100644 --- a/vendor/github.com/prometheus/tsdb/wal.go +++ b/vendor/github.com/prometheus/tsdb/wal.go @@ -99,9 +99,6 @@ type WALReader interface { type RefSeries struct { Ref uint64 Labels labels.Labels - - // hash for the label set. This field is not generally populated. - hash uint64 } // RefSample is a timestamp/value pair associated with a reference to a series. @@ -827,7 +824,9 @@ func (r *walReader) Read(seriesf SeriesCB, samplesf SamplesCB, deletesf DeletesC if err != nil { return errors.Wrap(err, "decode series entry") } - seriesf(series) + if err := seriesf(series); err != nil { + return err + } cf := r.current() @@ -842,7 +841,9 @@ func (r *walReader) Read(seriesf SeriesCB, samplesf SamplesCB, deletesf DeletesC if err != nil { return errors.Wrap(err, "decode samples entry") } - samplesf(samples) + if err := samplesf(samples); err != nil { + return err + } // Update the times for the WAL segment file. cf := r.current() @@ -858,7 +859,9 @@ func (r *walReader) Read(seriesf SeriesCB, samplesf SamplesCB, deletesf DeletesC if err != nil { return errors.Wrap(err, "decode delete entry") } - deletesf(stones) + if err := deletesf(stones); err != nil { + return err + } // Update the times for the WAL segment file. cf := r.current() diff --git a/vendor/vendor.json b/vendor/vendor.json index 907fb7e06..2b639724e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -871,22 +871,22 @@ "revisionTime": "2016-04-11T19:08:41Z" }, { - "checksumSHA1": "mDKxPAubVLTWW/Gar13m7YDHSek=", + "checksumSHA1": "B5ndMoK8lqgFJ8xUZ/0V4zCpUw0=", "path": "github.com/prometheus/tsdb", - "revision": "3870ec285c4640d462a0ad80e7acbcdf1e939563", - "revisionTime": "2017-09-11T08:41:33Z" + "revision": "162a48e4f2c6e486a0ebf61cf9cea73a8023ef0a", + "revisionTime": "2017-09-19T08:20:19Z" }, { "checksumSHA1": "Gua979gmISm4cJP/fR2hL8m5To8=", "path": "github.com/prometheus/tsdb/chunks", - "revision": "3870ec285c4640d462a0ad80e7acbcdf1e939563", - "revisionTime": "2017-09-11T08:41:33Z" + "revision": "162a48e4f2c6e486a0ebf61cf9cea73a8023ef0a", + "revisionTime": "2017-09-19T08:20:19Z" }, { "checksumSHA1": "zhmlvc322RH1L3l9DaA9d/HVVWs=", "path": "github.com/prometheus/tsdb/labels", - "revision": "3870ec285c4640d462a0ad80e7acbcdf1e939563", - "revisionTime": "2017-09-11T08:41:33Z" + "revision": "162a48e4f2c6e486a0ebf61cf9cea73a8023ef0a", + "revisionTime": "2017-09-19T08:20:19Z" }, { "checksumSHA1": "5SYLEhADhdBVZAGPVHWggQl7H8k=",