Update package tsdb/index for new labels.Labels type

Incomplete - needs further changes to `Decoder.Series()`.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2022-03-09 22:18:47 +00:00
parent 623d306f91
commit 927a14b0e9
2 changed files with 9 additions and 6 deletions

View file

@ -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) 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) 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 // 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.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 var err error
cacheEntry, ok := w.symbolCache[l.Name] cacheEntry, ok := w.symbolCache[l.Name]
nameIndex := cacheEntry.index nameIndex := cacheEntry.index
@ -465,6 +465,9 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ...
} }
} }
w.buf2.PutUvarint32(valueIndex) w.buf2.PutUvarint32(valueIndex)
return nil
}); err != nil {
return err
} }
w.buf2.PutUvarint(len(chunks)) 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") return errors.Wrap(err, "write series data")
} }
w.lastSeries = append(w.lastSeries[:0], lset...) w.lastSeries.CopyFrom(lset)
w.lastRef = ref w.lastRef = ref
return nil return nil

View file

@ -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) { func (p *MemPostings) Add(id storage.SeriesRef, lset labels.Labels) {
p.mtx.Lock() p.mtx.Lock()
for _, l := range lset { lset.Range(func(l labels.Label) {
p.addFor(id, l) p.addFor(id, l)
} })
p.addFor(id, allPostingsKey) p.addFor(id, allPostingsKey)
p.mtx.Unlock() p.mtx.Unlock()