mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* Add traceid index to vparquet2 and use it when finding trace by id * Update to detect when trace ID is beyond the last row group and bail * simplify * Add index to vparquet3 * go away * lint * changelog * Fix index to not flush duplicate entry, which could happen if the block ended on exactly the configured rowgroup size while flushing * the opposite of move fast and break things * more optionalality * Add new env var VPARQUET_INDEX=0 to disable the index lookup
49 lines
864 B
Go
49 lines
864 B
Go
package vparquet3
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"sort"
|
|
|
|
"github.com/grafana/tempo/tempodb/encoding/common"
|
|
)
|
|
|
|
type index struct {
|
|
lastID common.ID
|
|
dirty bool
|
|
RowGroups []common.ID `json:"rowGroups"`
|
|
}
|
|
|
|
func (i *index) Add(id common.ID) {
|
|
i.lastID = id
|
|
i.dirty = true
|
|
}
|
|
|
|
func (i *index) Flush() {
|
|
if i.dirty {
|
|
i.RowGroups = append(i.RowGroups, i.lastID)
|
|
i.dirty = false
|
|
}
|
|
}
|
|
|
|
func (i *index) Marshal() ([]byte, error) {
|
|
return json.Marshal(i)
|
|
}
|
|
|
|
func (i *index) Find(id common.ID) int {
|
|
n := sort.Search(len(i.RowGroups), func(j int) bool {
|
|
return bytes.Compare(id, i.RowGroups[j]) <= 0
|
|
})
|
|
if n >= len(i.RowGroups) {
|
|
// Beyond the last row group. This is the only
|
|
// area where presence can be ruled out.
|
|
return -1
|
|
}
|
|
return n
|
|
}
|
|
|
|
func unmarshalIndex(b []byte) (*index, error) {
|
|
i := &index{}
|
|
return i, json.Unmarshal(b, i)
|
|
}
|