Skip to content

Commit

Permalink
Removed stats updates which should be in stats PR
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Jan 2, 2024
1 parent e33f43f commit 0faf761
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,41 @@
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.
*
* @opensearch.internal
*/
public final class ShardRequestCache {

private EnumMap<TierType, StatsHolder> 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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndicesRequestCache.Key, BytesReference> 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);
}
}

0 comments on commit 0faf761

Please sign in to comment.