mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Write label value indices
This commit is contained in:
parent
1e0edf367b
commit
8cbc95c316
9
db.go
9
db.go
|
@ -291,6 +291,15 @@ func (s *SeriesShard) persist() error {
|
|||
if err := iw.WriteStats(nil); err != nil {
|
||||
return err
|
||||
}
|
||||
for n, v := range head.index.values {
|
||||
s := make([]string, 0, len(v))
|
||||
for x := range v {
|
||||
s = append(s, x)
|
||||
}
|
||||
|
||||
iw.WriteLabelIndex([]string{n}, s)
|
||||
|
||||
}
|
||||
|
||||
sz := fmt.Sprintf("%fMiB", float64(sw.Size()+iw.Size())/1024/1024)
|
||||
|
||||
|
|
31
writer.go
31
writer.go
|
@ -2,6 +2,7 @@ package tsdb
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"os"
|
||||
|
@ -175,14 +176,16 @@ type indexWriter struct {
|
|||
series []Labels
|
||||
offsets [][]ChunkOffset
|
||||
|
||||
symbols map[string]uint32
|
||||
symbols map[string]uint32 // symbol offsets
|
||||
labelIndexes map[string]uint32 // label index offsets
|
||||
}
|
||||
|
||||
func newIndexWriter(w io.Writer) *indexWriter {
|
||||
return &indexWriter{
|
||||
w: w,
|
||||
n: 0,
|
||||
symbols: make(map[string]uint32),
|
||||
w: w,
|
||||
n: 0,
|
||||
symbols: make(map[string]uint32),
|
||||
labelIndexes: make(map[string]uint32),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +254,25 @@ func (w *indexWriter) writeSymbols() error {
|
|||
}
|
||||
|
||||
func (w *indexWriter) WriteLabelIndex(names []string, values []string) error {
|
||||
return nil
|
||||
if len(names) != 1 {
|
||||
return fmt.Errorf("not supported")
|
||||
}
|
||||
sort.Strings(values)
|
||||
|
||||
h := crc32.NewIEEE()
|
||||
wr := io.MultiWriter(h, w.w)
|
||||
|
||||
w.labelIndexes[names[0]] = uint32(w.n)
|
||||
|
||||
for _, v := range values {
|
||||
o := w.symbols[v]
|
||||
|
||||
if err := w.write(wr, ((*[4]byte)(unsafe.Pointer(&o)))[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return w.write(w.w, h.Sum(nil))
|
||||
}
|
||||
|
||||
func (w *indexWriter) WriteSeries(ref uint32, ls ...Labels) error {
|
||||
|
|
Loading…
Reference in a new issue