Skip to content

Commit 2c1bef7

Browse files
committed
Version check added
Signed-off-by: tanishq ranjan <[email protected]>
1 parent 5fc979c commit 2c1bef7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

server/src/main/java/org/opensearch/index/store/remote/filecache/FileCacheStats.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.opensearch.index.store.remote.filecache;
1010

11+
import org.opensearch.Version;
1112
import org.opensearch.common.annotation.InternalApi;
1213
import org.opensearch.common.annotation.PublicApi;
1314
import org.opensearch.core.common.io.stream.StreamInput;
@@ -77,9 +78,16 @@ public FileCacheStats(final StreamInput in) throws IOException {
7778
this.used = in.readLong();
7879
this.pinned = in.readLong();
7980
this.evicted = in.readLong();
80-
this.removed = in.readLong();
8181
this.hits = in.readLong();
82-
this.misses = in.readLong();
82+
83+
// Version guard for enhanced fields - backward compatibility for rolling upgrades
84+
if (in.getVersion().onOrAfter(Version.V_3_3_0)) {
85+
this.removed = in.readLong();
86+
this.misses = in.readLong();
87+
} else {
88+
this.removed = 0L;
89+
this.misses = 0L;
90+
}
8391
}
8492

8593
@Override
@@ -90,9 +98,13 @@ public void writeTo(final StreamOutput out) throws IOException {
9098
out.writeLong(used);
9199
out.writeLong(pinned);
92100
out.writeLong(evicted);
93-
out.writeLong(removed);
94101
out.writeLong(hits);
95-
out.writeLong(misses);
102+
103+
// Version guard for enhanced fields - backward compatibility for rolling upgrades
104+
if (out.getVersion().onOrAfter(Version.V_3_3_0)) {
105+
out.writeLong(removed);
106+
out.writeLong(misses);
107+
}
96108
}
97109

98110
public long getActive() {
@@ -145,6 +157,7 @@ static final class Fields {
145157
static final String USED = "used";
146158
static final String PINNED = "pinned";
147159
static final String USED_IN_BYTES = "used_in_bytes";
160+
static final String PINNED_IN_BYTES = "pinned_in_bytes";
148161
static final String EVICTIONS = "evictions";
149162
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes";
150163
static final String REMOVED = "removed";
@@ -159,7 +172,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
159172
builder.startObject(statsType.toString());
160173
builder.humanReadableField(FileCacheStats.Fields.ACTIVE_IN_BYTES, FileCacheStats.Fields.ACTIVE, new ByteSizeValue(getActive()));
161174
builder.humanReadableField(FileCacheStats.Fields.USED_IN_BYTES, FileCacheStats.Fields.USED, new ByteSizeValue(getUsed()));
162-
builder.humanReadableField(FileCacheStats.Fields.USED_IN_BYTES, Fields.PINNED, new ByteSizeValue(getPinnedUsage()));
175+
builder.humanReadableField(FileCacheStats.Fields.PINNED_IN_BYTES, Fields.PINNED, new ByteSizeValue(getPinnedUsage()));
163176
builder.humanReadableField(
164177
FileCacheStats.Fields.EVICTIONS_IN_BYTES,
165178
FileCacheStats.Fields.EVICTIONS,

0 commit comments

Comments
 (0)