mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
tsdb: simplify internal series delete function (#13261)
Lifting an optimisation from Agent code, `seriesHashmap.del` can use the unique series reference, doesn't need to check Labels. Also streamline the logic for deleting from `unique` and `conflicts` maps, and add some comments to help the next person. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
74b73d1e2c
commit
b9eab6e4b8
23
tsdb/head.go
23
tsdb/head.go
|
@ -1751,32 +1751,31 @@ func (m *seriesHashmap) set(hash uint64, s *memSeries) {
|
|||
m.conflicts[hash] = append(l, s)
|
||||
}
|
||||
|
||||
func (m *seriesHashmap) del(hash uint64, lset labels.Labels) {
|
||||
func (m *seriesHashmap) del(hash uint64, ref chunks.HeadSeriesRef) {
|
||||
var rem []*memSeries
|
||||
unique, found := m.unique[hash]
|
||||
switch {
|
||||
case !found:
|
||||
case !found: // Supplied hash is not stored.
|
||||
return
|
||||
case labels.Equal(unique.lset, lset):
|
||||
case unique.ref == ref:
|
||||
conflicts := m.conflicts[hash]
|
||||
if len(conflicts) == 0 {
|
||||
if len(conflicts) == 0 { // Exactly one series with this hash was stored
|
||||
delete(m.unique, hash)
|
||||
return
|
||||
}
|
||||
rem = conflicts
|
||||
default:
|
||||
rem = append(rem, unique)
|
||||
m.unique[hash] = conflicts[0] // First remaining series goes in 'unique'.
|
||||
rem = conflicts[1:] // Keep the rest.
|
||||
default: // The series to delete is somewhere in 'conflicts'. Keep all the ones that don't match.
|
||||
for _, s := range m.conflicts[hash] {
|
||||
if !labels.Equal(s.lset, lset) {
|
||||
if s.ref != ref {
|
||||
rem = append(rem, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
m.unique[hash] = rem[0]
|
||||
if len(rem) == 1 {
|
||||
if len(rem) == 0 {
|
||||
delete(m.conflicts, hash)
|
||||
} else {
|
||||
m.conflicts[hash] = rem[1:]
|
||||
m.conflicts[hash] = rem
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1891,7 +1890,7 @@ func (s *stripeSeries) gc(mint int64, minOOOMmapRef chunks.ChunkDiskMapperRef) (
|
|||
}
|
||||
|
||||
deleted[storage.SeriesRef(series.ref)] = struct{}{}
|
||||
s.hashes[hashShard].del(hash, series.lset)
|
||||
s.hashes[hashShard].del(hash, series.ref)
|
||||
delete(s.series[refShard], series.ref)
|
||||
deletedForCallback[series.ref] = series.lset
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue