Skip to content

Commit

Permalink
Re-added old versions of onCached and onRemoval to ShardRequestCache
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Apr 29, 2024
1 parent 3030b81 commit 474c19f
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.index.cache.request;

import org.apache.lucene.util.Accountable;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.metrics.CounterMetric;
import org.opensearch.core.common.bytes.BytesReference;
Expand Down Expand Up @@ -61,6 +62,7 @@ public void onMiss() {
missCount.inc();
}

// Functions used to increment size by passing in the size directly, Used now, as we use ICacheKey<Key> in the IndicesRequestCache..
public void onCached(long keyRamBytesUsed, BytesReference value) {
totalMetric.inc(keyRamBytesUsed + value.ramBytesUsed());
}
Expand All @@ -75,4 +77,22 @@ public void onRemoval(long keyRamBytesUsed, BytesReference value, boolean evicte
}
totalMetric.dec(dec);
}

// Old functions which increment size by passing in an Accountable. Functional but no longer used.
public void onCached(Accountable key, BytesReference value) {
totalMetric.inc(key.ramBytesUsed() + value.ramBytesUsed());
}

public void onRemoval(Accountable key, BytesReference value, boolean evicted) {
if (evicted) {
evictionsMetric.inc();
}
long dec = 0;
if (key != null) {
dec += key.ramBytesUsed();
}
if (value != null) {
dec += value.ramBytesUsed();
}
}
}

0 comments on commit 474c19f

Please sign in to comment.