mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix hashmap serialization
This commit is contained in:
parent
14dbc59f2b
commit
8425df035d
23
writer.go
23
writer.go
|
@ -59,7 +59,7 @@ func (w *seriesWriter) write(wr io.Writer, b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *seriesWriter) writeMeta() error {
|
func (w *seriesWriter) writeMeta() error {
|
||||||
b := [64]byte{}
|
b := [8]byte{}
|
||||||
|
|
||||||
binary.BigEndian.PutUint32(b[:4], MagicSeries)
|
binary.BigEndian.PutUint32(b[:4], MagicSeries)
|
||||||
b[4] = flagStd
|
b[4] = flagStd
|
||||||
|
@ -79,16 +79,15 @@ func (w *seriesWriter) WriteSeries(ref uint32, lset Labels, chks []*chunkDesc) e
|
||||||
h := crc32.NewIEEE()
|
h := crc32.NewIEEE()
|
||||||
wr := io.MultiWriter(h, w.w)
|
wr := io.MultiWriter(h, w.w)
|
||||||
|
|
||||||
l := 0
|
// For normal reads we don't need the number of the chunk section but
|
||||||
for _, cd := range chks {
|
|
||||||
l += len(cd.chunk.Bytes())
|
|
||||||
}
|
|
||||||
// For normal reads we don't need the length of the chunk section but
|
|
||||||
// it allows us to verify checksums without reading the index file.
|
// it allows us to verify checksums without reading the index file.
|
||||||
b := [4]byte{}
|
// The offsets are also technically enough to calculate chunk size. but
|
||||||
binary.BigEndian.PutUint32(b[:], uint32(l))
|
// holding the length of each chunk could later allow for adding padding
|
||||||
|
// between chunks.
|
||||||
|
b := [binary.MaxVarintLen32]byte{}
|
||||||
|
n := binary.PutUvarint(b[:], uint64(len(chks)))
|
||||||
|
|
||||||
if err := w.write(wr, b[:]); err != nil {
|
if err := w.write(wr, b[:n]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +99,11 @@ func (w *seriesWriter) WriteSeries(ref uint32, lset Labels, chks []*chunkDesc) e
|
||||||
Value: lastTimestamp,
|
Value: lastTimestamp,
|
||||||
Offset: uint32(w.n),
|
Offset: uint32(w.n),
|
||||||
})
|
})
|
||||||
|
n = binary.PutUvarint(b[:], uint64(len(cd.chunk.Bytes())))
|
||||||
|
|
||||||
|
if err := w.write(wr, b[:n]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := w.write(wr, []byte{byte(cd.chunk.Encoding())}); err != nil {
|
if err := w.write(wr, []byte{byte(cd.chunk.Encoding())}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -229,7 +232,7 @@ func (w *indexWriter) section(l uint32, flag byte, f func(w io.Writer) error) er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *indexWriter) writeMeta() error {
|
func (w *indexWriter) writeMeta() error {
|
||||||
b := [64]byte{}
|
b := [8]byte{}
|
||||||
|
|
||||||
binary.BigEndian.PutUint32(b[:4], MagicIndex)
|
binary.BigEndian.PutUint32(b[:4], MagicIndex)
|
||||||
b[4] = flagStd
|
b[4] = flagStd
|
||||||
|
|
Loading…
Reference in a new issue