Skip to content

Commit

Permalink
Change native histogram custom trackers into maps
Browse files Browse the repository at this point in the history
  • Loading branch information
zenador committed Aug 29, 2023
1 parent dc01c92 commit fa984d2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/ingester/activeseries/active_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ type seriesStripe struct {

mu sync.RWMutex
refs map[storage.SeriesRef]seriesEntry
active uint32 // Number of active entries in this stripe. Only decreased during purge or clear.
activeMatching []uint32 // Number of active entries in this stripe matching each matcher of the configured Matchers.
activeNativeHistograms uint32 // Number of active entries (only native histograms) in this stripe. Only decreased during purge or clear.
activeMatchingNativeHistograms []uint32 // Number of active entries (only native histograms) in this stripe matching each matcher of the configured Matchers.
activeNativeHistogramBuckets uint32 // Number of buckets in active native histogram entries in this stripe. Only decreased during purge or clear.
activeMatchingNativeHistogramBuckets []uint32 // Number of buckets in active native histogram entries in this stripe matching each matcher of the configured Matchers.
active uint32 // Number of active entries in this stripe. Only decreased during purge or clear.
activeMatching []uint32 // Number of active entries in this stripe matching each matcher of the configured Matchers.
activeNativeHistograms uint32 // Number of active entries (only native histograms) in this stripe. Only decreased during purge or clear.
activeMatchingNativeHistograms map[uint16]uint32 // Number of active entries (only native histograms) in this stripe matching each matcher of the configured Matchers.
activeNativeHistogramBuckets uint32 // Number of buckets in active native histogram entries in this stripe. Only decreased during purge or clear.
activeMatchingNativeHistogramBuckets map[uint16]uint32 // Number of buckets in active native histogram entries in this stripe matching each matcher of the configured Matchers.
}

// seriesEntry holds a timestamp for single series.
Expand Down Expand Up @@ -377,9 +377,9 @@ func (s *seriesStripe) clear() {
s.activeNativeHistogramBuckets = 0
for i := range s.activeMatching {
s.activeMatching[i] = 0
s.activeMatchingNativeHistograms[i] = 0
s.activeMatchingNativeHistogramBuckets[i] = 0
}
s.activeMatchingNativeHistograms = reinitMap()
s.activeMatchingNativeHistogramBuckets = reinitMap()
}

// Reinitialize assigns new matchers and corresponding size activeMatching slices.
Expand All @@ -395,8 +395,8 @@ func (s *seriesStripe) reinitialize(asm *Matchers, deleted *deletedSeries) {
s.activeNativeHistogramBuckets = 0
s.matchers = asm
s.activeMatching = resizeAndClear(len(asm.MatcherNames()), s.activeMatching)
s.activeMatchingNativeHistograms = resizeAndClear(len(asm.MatcherNames()), s.activeMatchingNativeHistograms)
s.activeMatchingNativeHistogramBuckets = resizeAndClear(len(asm.MatcherNames()), s.activeMatchingNativeHistogramBuckets)
s.activeMatchingNativeHistograms = reinitMap()
s.activeMatchingNativeHistogramBuckets = reinitMap()
}

func (s *seriesStripe) purge(keepUntil time.Time) {
Expand All @@ -413,8 +413,8 @@ func (s *seriesStripe) purge(keepUntil time.Time) {
s.activeNativeHistograms = 0
s.activeNativeHistogramBuckets = 0
s.activeMatching = resizeAndClear(len(s.activeMatching), s.activeMatching)
s.activeMatchingNativeHistograms = resizeAndClear(len(s.activeMatchingNativeHistograms), s.activeMatchingNativeHistograms)
s.activeMatchingNativeHistogramBuckets = resizeAndClear(len(s.activeMatchingNativeHistogramBuckets), s.activeMatchingNativeHistogramBuckets)
s.activeMatchingNativeHistograms = reinitMap()
s.activeMatchingNativeHistogramBuckets = reinitMap()

oldest := int64(math.MaxInt64)
for ref, entry := range s.refs {
Expand Down Expand Up @@ -503,6 +503,10 @@ func resizeAndClear(l int, prev []uint32) []uint32 {
return p
}

func reinitMap() map[uint16]uint32 {
return make(map[uint16]uint32)
}

type deletedSeries struct {
mu sync.RWMutex
keys map[storage.SeriesRef]string
Expand Down

0 comments on commit fa984d2

Please sign in to comment.