Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
loki/pkg/ingester/checkpoint.go

62 lines
1.3 KiB

package ingester
import (
"time"
"github.com/grafana/loki/pkg/chunkenc"
)
// The passed wireChunks slice is for re-use.
// nolint(deadcode)
func toWireChunks(descs []*chunkDesc, wireChunks []Chunk) ([]Chunk, error) {
if cap(wireChunks) < len(descs) {
wireChunks = make([]Chunk, len(descs))
} else {
wireChunks = wireChunks[:len(descs)]
}
for i, d := range descs {
from, to := d.chunk.Bounds()
wireChunk := Chunk{
From: from,
To: to,
Closed: d.closed,
FlushedAt: d.flushed,
}
slice := wireChunks[i].Data[:0] // try to re-use the memory from last time
if cap(slice) < d.chunk.CompressedSize() {
slice = make([]byte, 0, d.chunk.CompressedSize())
}
out, err := d.chunk.BytesWith(slice)
if err != nil {
return nil, err
}
wireChunk.Data = out
wireChunks[i] = wireChunk
}
return wireChunks, nil
}
// nolint(deadcode)
func fromWireChunks(conf *Config, wireChunks []Chunk) ([]*chunkDesc, error) {
descs := make([]*chunkDesc, 0, len(wireChunks))
for _, c := range wireChunks {
desc := &chunkDesc{
closed: c.Closed,
flushed: c.FlushedAt,
lastUpdated: time.Now(),
}
mc, err := chunkenc.NewByteChunk(c.Data, conf.BlockSize, conf.TargetChunkSize)
if err != nil {
return nil, err
}
desc.chunk = mc
descs = append(descs, desc)
}
return descs, nil
}