Skip to content

Commit

Permalink
[Tiered Caching] Bump versions for serialization in new cache stats A…
Browse files Browse the repository at this point in the history
…PI (#13460)


---------

Signed-off-by: Peter Alfonsi <petealft@amazon.com>
Co-authored-by: Peter Alfonsi <petealft@amazon.com>
  • Loading branch information
peteralfonsi and Peter Alfonsi authored Apr 30, 2024
1 parent 1219c56 commit 8ac92d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public NodeStats(StreamInput in) throws IOException {
} else {
admissionControlStats = null;
}
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_14_0)) {
nodeCacheStats = in.readOptionalWriteable(NodeCacheStats::new);
} else {
nodeCacheStats = null;
Expand Down Expand Up @@ -522,7 +522,7 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_12_0)) {
out.writeOptionalWriteable(admissionControlStats);
}
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_14_0)) {
out.writeOptionalWriteable(nodeCacheStats);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public CommonStatsFlags(StreamInput in) throws IOException {
includeUnloadedSegments = in.readBoolean();
includeAllShardIndexingPressureTrackers = in.readBoolean();
includeOnlyTopIndexingPressureMetrics = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_14_0)) {
includeCaches = in.readEnumSet(CacheType.class);
levels = in.readStringArray();
}
Expand All @@ -120,7 +120,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(includeUnloadedSegments);
out.writeBoolean(includeAllShardIndexingPressureTrackers);
out.writeBoolean(includeOnlyTopIndexingPressureMetrics);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_14_0)) {
out.writeEnumSet(includeCaches);
out.writeStringArrayNullable(levels);
}
Expand Down
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 8ac92d4

Please sign in to comment.