Browse Source

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>
pull/13463/head^2
Bryan Boreham 10 months ago committed by GitHub
parent
commit
b9eab6e4b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 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…
Cancel
Save