Skip to content

Commit 8ac92d4

Browse files
peteralfonsiPeter Alfonsi
and
Peter Alfonsi
authored
[Tiered Caching] Bump versions for serialization in new cache stats API (opensearch-project#13460)
--------- Signed-off-by: Peter Alfonsi <petealft@amazon.com> Co-authored-by: Peter Alfonsi <petealft@amazon.com>
1 parent 1219c56 commit 8ac92d4

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

server/src/main/java/org/opensearch/action/admin/cluster/node/stats/NodeStats.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public NodeStats(StreamInput in) throws IOException {
238238
} else {
239239
admissionControlStats = null;
240240
}
241-
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
241+
if (in.getVersion().onOrAfter(Version.V_2_14_0)) {
242242
nodeCacheStats = in.readOptionalWriteable(NodeCacheStats::new);
243243
} else {
244244
nodeCacheStats = null;
@@ -522,7 +522,7 @@ public void writeTo(StreamOutput out) throws IOException {
522522
if (out.getVersion().onOrAfter(Version.V_2_12_0)) {
523523
out.writeOptionalWriteable(admissionControlStats);
524524
}
525-
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
525+
if (out.getVersion().onOrAfter(Version.V_2_14_0)) {
526526
out.writeOptionalWriteable(nodeCacheStats);
527527
}
528528
}

server/src/main/java/org/opensearch/action/admin/indices/stats/CommonStatsFlags.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public CommonStatsFlags(StreamInput in) throws IOException {
9696
includeUnloadedSegments = in.readBoolean();
9797
includeAllShardIndexingPressureTrackers = in.readBoolean();
9898
includeOnlyTopIndexingPressureMetrics = in.readBoolean();
99-
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
99+
if (in.getVersion().onOrAfter(Version.V_2_14_0)) {
100100
includeCaches = in.readEnumSet(CacheType.class);
101101
levels = in.readStringArray();
102102
}
@@ -120,7 +120,7 @@ public void writeTo(StreamOutput out) throws IOException {
120120
out.writeBoolean(includeUnloadedSegments);
121121
out.writeBoolean(includeAllShardIndexingPressureTrackers);
122122
out.writeBoolean(includeOnlyTopIndexingPressureMetrics);
123-
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
123+
if (out.getVersion().onOrAfter(Version.V_2_14_0)) {
124124
out.writeEnumSet(includeCaches);
125125
out.writeStringArrayNullable(levels);
126126
}

server/src/main/java/org/opensearch/index/cache/request/ShardRequestCache.java

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
package org.opensearch.index.cache.request;
3434

35+
import org.apache.lucene.util.Accountable;
3536
import org.opensearch.common.annotation.PublicApi;
3637
import org.opensearch.common.metrics.CounterMetric;
3738
import org.opensearch.core.common.bytes.BytesReference;
@@ -61,6 +62,7 @@ public void onMiss() {
6162
missCount.inc();
6263
}
6364

65+
// Functions used to increment size by passing in the size directly, Used now, as we use ICacheKey<Key> in the IndicesRequestCache..
6466
public void onCached(long keyRamBytesUsed, BytesReference value) {
6567
totalMetric.inc(keyRamBytesUsed + value.ramBytesUsed());
6668
}
@@ -75,4 +77,22 @@ public void onRemoval(long keyRamBytesUsed, BytesReference value, boolean evicte
7577
}
7678
totalMetric.dec(dec);
7779
}
80+
81+
// Old functions which increment size by passing in an Accountable. Functional but no longer used.
82+
public void onCached(Accountable key, BytesReference value) {
83+
totalMetric.inc(key.ramBytesUsed() + value.ramBytesUsed());
84+
}
85+
86+
public void onRemoval(Accountable key, BytesReference value, boolean evicted) {
87+
if (evicted) {
88+
evictionsMetric.inc();
89+
}
90+
long dec = 0;
91+
if (key != null) {
92+
dec += key.ramBytesUsed();
93+
}
94+
if (value != null) {
95+
dec += value.ramBytesUsed();
96+
}
97+
}
7898
}

0 commit comments

Comments
 (0)