Repository: prometheus/prometheus
File: tsdb/head.go (Go)

Code before:
			// All series should be flushed
			flushedForCallback[s.ref] = s.lset
		})
		h.metrics.seriesRemoved.Add(float64(fs))
	}

	h.series = newStripeSeries(h.opts.StripeSize, h.opts.SeriesCallback)
	h.iso = newIsolation(h.opts.IsolationDisabled)
	h.oooIso = newOOOIsolation()
	h.numSeries.Store(0)
	h.exemplarMetrics = em
	h.exemplars = es
	h.postings = index.NewUnorderedMemPostings()
	h.tombstones = tombstones.NewMemTombstones()
	h.deleted = map[chunks.HeadSeriesRef]int{}
	h.chunkRange.Store(h.opts.ChunkRange)
	h.minTime.Store(math.MaxInt64)
	h.maxTime.Store(math.MinInt64)
	h.minOOOTime.Store(math.MaxInt64)
	h.maxOOOTime.Store(math.MinInt64)
	h.lastWALTruncationTime.Store(math.MinInt64)
	h.lastMemoryTruncationTime.Store(math.MinInt64)
	return nil
}

func (h *Head) resetWLReplayResources() {
	h.wlReplaySeriesPool = zeropool.Pool[[]record.RefSeries]{}
	h.wlReplaySamplesPool = zeropool.Pool[[]record.RefSample]{}
	h.wlReplaytStonesPool = zeropool.Pool[[]tombstones.Stone]{}
	h.wlReplayExemplarsPool = zeropool.Pool[[]record.RefExemplar]{}
	h.wlReplayHistogramsPool = zeropool.Pool[[]record.RefHistogramSample]{}
	h.wlReplayFloatHistogramsPool = zeropool.Pool[[]record.RefFloatHistogramSample]{}
	h.wlReplayMetadataPool = zeropool.Pool[[]record.RefMetadata]{}
	h.wlReplayMmapMarkersPool = zeropool.Pool[[]record.RefMmapMarker]{}
}

type headMetrics struct {
	activeAppenders           prometheus.Gauge
	series                    prometheus.GaugeFunc
	seriesCreated             prometheus.Counter
	seriesRemoved             prometheus.Counter
	seriesNotFound            prometheus.Counter
	chunks                    prometheus.Gauge
	chunksCreated             prometheus.Counter
	chunksRemoved             prometheus.Counter
	gcDuration                prometheus.Summary
	samplesAppended           *prometheus.CounterVec
	outOfOrderSamplesAppended *prometheus.CounterVec
	outOfBoundSamples         *prometheus.CounterVec
	outOfOrderSamples         *prometheus.CounterVec
	tooOldSamples             *prometheus.CounterVec

Review comment (refactor):
I doubt this is needed. In fact I suspect this actually only increase allocs and the GC is removing objs from inside pools in the next GC iteration (due to victim area implementation mentioned in https://victoriametrics.com/blog/go-sync-pool/). 

Unless we can prove it e.g. with some experiment, I think I would remove this.

Code after:
			flushedForCallback[s.ref] = s.lset
		})
		h.metrics.seriesRemoved.Add(float64(fs))
	}

	h.series = newStripeSeries(h.opts.StripeSize, h.opts.SeriesCallback)
	h.iso = newIsolation(h.opts.IsolationDisabled)
	h.oooIso = newOOOIsolation()
	h.numSeries.Store(0)
	h.exemplarMetrics = em
	h.exemplars = es
	h.postings = index.NewUnorderedMemPostings()
	h.tombstones = tombstones.NewMemTombstones()
	h.deleted = map[chunks.HeadSeriesRef]int{}
	h.chunkRange.Store(h.opts.ChunkRange)
	h.minTime.Store(math.MaxInt64)
	h.maxTime.Store(math.MinInt64)
	h.minOOOTime.Store(math.MaxInt64)
	h.maxOOOTime.Store(math.MinInt64)
	h.lastWALTruncationTime.Store(math.MinInt64)
	h.lastMemoryTruncationTime.Store(math.MinInt64)
	return nil
}

type headMetrics struct {
	activeAppenders           prometheus.Gauge
	series                    prometheus.GaugeFunc
	seriesCreated             prometheus.Counter
	seriesRemoved             prometheus.Counter
	seriesNotFound            prometheus.Counter
	chunks                    prometheus.Gauge
	chunksCreated             prometheus.Counter
	chunksRemoved             prometheus.Counter
	gcDuration                prometheus.Summary
	samplesAppended           *prometheus.CounterVec
	outOfOrderSamplesAppended *prometheus.CounterVec
	outOfBoundSamples         *prometheus.CounterVec
	outOfOrderSamples         *prometheus.CounterVec
	tooOldSamples             *prometheus.CounterVec
	walTruncateDuration       prometheus.Summary
	walCorruptionsTotal       prometheus.Counter
	dataTotalReplayDuration   prometheus.Gauge
	headTruncateFail          prometheus.Counter
	headTruncateTotal         prometheus.Counter
	checkpointDeleteFail      prometheus.Counter
	checkpointDeleteTotal     prometheus.Counter
	checkpointCreationFail    prometheus.Counter
	checkpointCreationTotal   prometheus.Counter
	mmapChunkCorruptionTotal  prometheus.Counter
	snapshotReplayErrorTotal  prometheus.Counter // Will be either 0 or 1.
	oooHistogram              prometheus.Histogram