From 927a14b0e9f575b46163114c202d1470962d262c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 9 Mar 2022 22:18:47 +0000 Subject: [PATCH] Update package tsdb/index for new labels.Labels type Incomplete - needs further changes to `Decoder.Series()`. Signed-off-by: Bryan Boreham --- tsdb/index/index.go | 11 +++++++---- tsdb/index/postings.go | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tsdb/index/index.go b/tsdb/index/index.go index 9d7897860..ba78b5712 100644 --- a/tsdb/index/index.go +++ b/tsdb/index/index.go @@ -423,7 +423,7 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ... return errors.Errorf("out-of-order series added with label set %q", lset) } - if ref < w.lastRef && len(w.lastSeries) != 0 { + if ref < w.lastRef && !w.lastSeries.IsEmpty() { return errors.Errorf("series with reference greater than %d already added", ref) } // We add padding to 16 bytes to increase the addressable space we get through 4 byte @@ -437,9 +437,9 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ... } w.buf2.Reset() - w.buf2.PutUvarint(len(lset)) + w.buf2.PutUvarint(lset.Len()) - for _, l := range lset { + if err := lset.Validate(func(l labels.Label) error { var err error cacheEntry, ok := w.symbolCache[l.Name] nameIndex := cacheEntry.index @@ -465,6 +465,9 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ... } } w.buf2.PutUvarint32(valueIndex) + return nil + }); err != nil { + return err } w.buf2.PutUvarint(len(chunks)) @@ -496,7 +499,7 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ... return errors.Wrap(err, "write series data") } - w.lastSeries = append(w.lastSeries[:0], lset...) + w.lastSeries.CopyFrom(lset) w.lastRef = ref return nil diff --git a/tsdb/index/postings.go b/tsdb/index/postings.go index 22e85ab36..64574f85c 100644 --- a/tsdb/index/postings.go +++ b/tsdb/index/postings.go @@ -353,9 +353,9 @@ func (p *MemPostings) Iter(f func(labels.Label, Postings) error) error { func (p *MemPostings) Add(id storage.SeriesRef, lset labels.Labels) { p.mtx.Lock() - for _, l := range lset { + lset.Range(func(l labels.Label) { p.addFor(id, l) - } + }) p.addFor(id, allPostingsKey) p.mtx.Unlock()