diff --git a/src/OpenTelemetry/Metrics/AggregatorStore.cs b/src/OpenTelemetry/Metrics/AggregatorStore.cs index ca71b6f10d5..c74c2ff25b0 100644 --- a/src/OpenTelemetry/Metrics/AggregatorStore.cs +++ b/src/OpenTelemetry/Metrics/AggregatorStore.cs @@ -297,9 +297,7 @@ internal void SnapshotDeltaWithMetricPointReclaim() { var lookupData = metricPoint.LookupData; - // Setting `LookupData` to `null` to denote that this MetricPoint is reclaimed. - // Snapshot method can use this to skip trying to reclaim indices which have already been reclaimed and added to the queue. - metricPoint.LookupData = null; + metricPoint.Reclaim(); Debug.Assert(this.TagsToMetricPointIndexDictionaryDelta != null, "this.tagsToMetricPointIndexDictionaryDelta was null"); diff --git a/src/OpenTelemetry/Metrics/MetricPoint.cs b/src/OpenTelemetry/Metrics/MetricPoint.cs index 2ccba6a307a..e1fe8e1695c 100644 --- a/src/OpenTelemetry/Metrics/MetricPoint.cs +++ b/src/OpenTelemetry/Metrics/MetricPoint.cs @@ -19,11 +19,6 @@ public struct MetricPoint // ReferenceCount doesn't matter for MetricPoint with no tags and overflow attribute as they are never reclaimed. internal int ReferenceCount; - // When the AggregatorStore is reclaiming MetricPoints, this serves the purpose of validating the a given thread is using the right - // MetricPoint for update by checking it against what as added in the Dictionary. Also, when a thread finds out that the MetricPoint - // that its using is already reclaimed, this helps avoid sorting of the tags for adding a new Dictionary entry. - internal LookupData? LookupData; - private const int DefaultSimpleReservoirPoolSize = 1; private readonly AggregatorStore aggregatorStore; @@ -155,6 +150,12 @@ internal MetricPointStatus MetricPointStatus private set; } + // When the AggregatorStore is reclaiming MetricPoints, this serves the purpose of validating the a given thread is using the right + // MetricPoint for update by checking it against what as added in the Dictionary. Also, when a thread finds out that the MetricPoint + // that its using is already reclaimed, this helps avoid sorting of the tags for adding a new Dictionary entry. + // Snapshot method can use this to skip trying to reclaim indices which have already been reclaimed and added to the queue. + internal LookupData? LookupData { readonly get; private set; } + internal readonly bool IsInitialized => this.aggregatorStore != null; /// @@ -1195,6 +1196,15 @@ internal void TakeSnapshotWithExemplar(bool outputDelta) } } + /// + /// Denote that this MetricPoint is reclaimed. + /// + internal void Reclaim() + { + this.LookupData = null; + this.mpComponents = null; + } + private void UpdateHistogram(double number, ReadOnlySpan> tags = default, bool isSampled = false) { Debug.Assert(this.mpComponents?.HistogramBuckets != null, "HistogramBuckets was null");