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 {
|
if err := iw.WriteStats(nil); err != nil {
|
||||||
return err
|
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)
|
sz := fmt.Sprintf("%fMiB", float64(sw.Size()+iw.Size())/1024/1024)
|
||||||
|
|
||||||
|
|
31
writer.go
31
writer.go
|
@ -2,6 +2,7 @@ package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -175,14 +176,16 @@ type indexWriter struct {
|
||||||
series []Labels
|
series []Labels
|
||||||
offsets [][]ChunkOffset
|
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 {
|
func newIndexWriter(w io.Writer) *indexWriter {
|
||||||
return &indexWriter{
|
return &indexWriter{
|
||||||
w: w,
|
w: w,
|
||||||
n: 0,
|
n: 0,
|
||||||
symbols: make(map[string]uint32),
|
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 {
|
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 {
|
func (w *indexWriter) WriteSeries(ref uint32, ls ...Labels) error {
|
||||||
|
|
Loading…
Reference in New Issue