From 0faf76185844ae5c60d886e14d4ed1d5d37da95c Mon Sep 17 00:00:00 2001 From: Peter Alfonsi Date: Tue, 2 Jan 2024 10:20:42 -0800 Subject: [PATCH] Removed stats updates which should be in stats PR Signed-off-by: Peter Alfonsi --- .../cache/request/ShardRequestCache.java | 47 ++++++------------- .../AbstractIndexShardCacheEntity.java | 17 ++++--- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/cache/request/ShardRequestCache.java b/server/src/main/java/org/opensearch/index/cache/request/ShardRequestCache.java index efad437804bef..795d585d88647 100644 --- a/server/src/main/java/org/opensearch/index/cache/request/ShardRequestCache.java +++ b/server/src/main/java/org/opensearch/index/cache/request/ShardRequestCache.java @@ -33,12 +33,9 @@ package org.opensearch.index.cache.request; import org.apache.lucene.util.Accountable; -import org.opensearch.common.cache.tier.TierType; import org.opensearch.common.metrics.CounterMetric; import org.opensearch.core.common.bytes.BytesReference; -import java.util.EnumMap; - /** * Tracks the portion of the request cache in use for a particular shard. * @@ -46,39 +43,31 @@ */ public final class ShardRequestCache { - private EnumMap statsHolder = new EnumMap<>(TierType.class); - - public ShardRequestCache() { - for (TierType tierType : TierType.values()) { - statsHolder.put(tierType, new StatsHolder()); - } - } + final CounterMetric evictionsMetric = new CounterMetric(); + final CounterMetric totalMetric = new CounterMetric(); + final CounterMetric hitCount = new CounterMetric(); + final CounterMetric missCount = new CounterMetric(); public RequestCacheStats stats() { // TODO: Change RequestCacheStats to support disk tier stats. - return new RequestCacheStats( - statsHolder.get(TierType.ON_HEAP).totalMetric.count(), - statsHolder.get(TierType.ON_HEAP).evictionsMetric.count(), - statsHolder.get(TierType.ON_HEAP).hitCount.count(), - statsHolder.get(TierType.ON_HEAP).missCount.count() - ); + return new RequestCacheStats(totalMetric.count(), evictionsMetric.count(), hitCount.count(), missCount.count()); } - public void onHit(TierType tierType) { - statsHolder.get(tierType).hitCount.inc(); + public void onHit() { + hitCount.inc(); } - public void onMiss(TierType tierType) { - statsHolder.get(tierType).missCount.inc(); + public void onMiss() { + missCount.inc(); } - public void onCached(Accountable key, BytesReference value, TierType tierType) { - statsHolder.get(tierType).totalMetric.inc(key.ramBytesUsed() + value.ramBytesUsed()); + public void onCached(Accountable key, BytesReference value) { + totalMetric.inc(key.ramBytesUsed() + value.ramBytesUsed()); } - public void onRemoval(Accountable key, BytesReference value, boolean evicted, TierType tierType) { + public void onRemoval(Accountable key, BytesReference value, boolean evicted) { if (evicted) { - statsHolder.get(tierType).evictionsMetric.inc(); + evictionsMetric.inc(); } long dec = 0; if (key != null) { @@ -87,14 +76,6 @@ public void onRemoval(Accountable key, BytesReference value, boolean evicted, Ti if (value != null) { dec += value.ramBytesUsed(); } - statsHolder.get(tierType).totalMetric.dec(dec); - } - - static class StatsHolder { - - final CounterMetric evictionsMetric = new CounterMetric(); - final CounterMetric totalMetric = new CounterMetric(); - final CounterMetric hitCount = new CounterMetric(); - final CounterMetric missCount = new CounterMetric(); + totalMetric.dec(dec); } } diff --git a/server/src/main/java/org/opensearch/indices/AbstractIndexShardCacheEntity.java b/server/src/main/java/org/opensearch/indices/AbstractIndexShardCacheEntity.java index d9c256b4b4a94..81d4f545e0fd9 100644 --- a/server/src/main/java/org/opensearch/indices/AbstractIndexShardCacheEntity.java +++ b/server/src/main/java/org/opensearch/indices/AbstractIndexShardCacheEntity.java @@ -53,26 +53,25 @@ abstract class AbstractIndexShardCacheEntity implements IndicesRequestCache.Cach @Override public final void onCached(IndicesRequestCache.Key key, BytesReference value, TierType tierType) { - stats().onCached(key, value, tierType); + // TODO: Handle tierType in stats + stats().onCached(key, value); } @Override public final void onHit(TierType tierType) { - stats().onHit(tierType); + // TODO: Handle tierType in stats + stats().onHit(); } @Override public final void onMiss(TierType tierType) { - stats().onMiss(tierType); + // TODO: Handle tierType in stats + stats().onMiss(); } @Override public final void onRemoval(RemovalNotification notification) { - stats().onRemoval( - notification.getKey(), - notification.getValue(), - notification.getRemovalReason() == RemovalReason.EVICTED, - notification.getTierType() - ); + // TODO: Handle tierType in stats + stats().onRemoval(notification.getKey(), notification.getValue(), notification.getRemovalReason() == RemovalReason.EVICTED); } }