Skip to content

Commit

Permalink
Add Head.RebuildSymbolTable
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Boreham <[email protected]>
  • Loading branch information
bboreham committed Feb 27, 2024
1 parent 114b324 commit 5d930ed
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tsdb/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -2418,3 +2418,34 @@ func (h *Head) ForEachSecondaryHash(fn func(secondaryHash []uint32)) {
}
}
}

// Go through all the series in h, build a SymbolTable with all names and values,
// replace each series' Labels with one using that SymbolTable.
func (h *Head) RebuildSymbolTable() *labels.SymbolTable {
st := labels.NewSymbolTable()
builder := labels.NewScratchBuilderWithSymbolTable(st, 0)
rebuildLabels := func(lbls labels.Labels) labels.Labels {
builder.Reset()
lbls.Range(func(l labels.Label) {
builder.Add(l.Name, l.Value)
})
return builder.Labels()
}

for i := 0; i < h.series.size; i++ {
h.series.locks[i].Lock()

for _, s := range h.series.hashes[i].unique {
s.lset = rebuildLabels(s.lset)
}

for _, all := range h.series.hashes[i].conflicts {
for _, s := range all {
s.lset = rebuildLabels(s.lset)
}
}

h.series.locks[i].Unlock()
}
return st
}

0 comments on commit 5d930ed

Please sign in to comment.