Skip to content

Commit a0a40bd

Browse files
authored
Add miss_count and removed_in_bytes fields in /_nodes/stats/file_cache API and fix used_in_bytes field collision (#19656)
Signed-off-by: tanishq ranjan <[email protected]>
1 parent 0d17990 commit a0a40bd

File tree

11 files changed

+81
-24
lines changed

11 files changed

+81
-24
lines changed

server/src/internalClusterTest/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ private static AggregateFileCacheStats setAggregateFileCacheStats(long active, l
750750
0,
751751
0,
752752
0,
753+
0,
753754
AggregateFileCacheStats.FileCacheStatsType.OVER_ALL_STATS
754755
);
755756
FileCacheStats fullStats = new FileCacheStats(
@@ -760,6 +761,7 @@ private static AggregateFileCacheStats setAggregateFileCacheStats(long active, l
760761
0,
761762
0,
762763
0,
764+
0,
763765
AggregateFileCacheStats.FileCacheStatsType.FULL_FILE_STATS
764766
);
765767
FileCacheStats blockStats = new FileCacheStats(
@@ -770,6 +772,7 @@ private static AggregateFileCacheStats setAggregateFileCacheStats(long active, l
770772
0,
771773
0,
772774
0,
775+
0,
773776
AggregateFileCacheStats.FileCacheStatsType.BLOCK_FILE_STATS
774777
);
775778
FileCacheStats pinnedStats = new FileCacheStats(
@@ -780,6 +783,7 @@ private static AggregateFileCacheStats setAggregateFileCacheStats(long active, l
780783
0,
781784
0,
782785
0,
786+
0,
783787
AggregateFileCacheStats.FileCacheStatsType.PINNED_FILE_STATS
784788
);
785789
return new AggregateFileCacheStats(System.currentTimeMillis(), overallStats, fullStats, blockStats, pinnedStats);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public ByteSizeValue getEvicted() {
116116
return new ByteSizeValue(overallFileCacheStats.getEvicted());
117117
}
118118

119+
public ByteSizeValue getRemoved() {
120+
return new ByteSizeValue(overallFileCacheStats.getRemoved());
121+
}
122+
119123
public long getCacheHits() {
120124
return overallFileCacheStats.getCacheHits();
121125
}
@@ -138,6 +142,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
138142
builder.humanReadableField(Fields.USED_IN_BYTES, Fields.USED, getUsed());
139143
builder.humanReadableField(Fields.PINNED_IN_BYTES, Fields.PINNED, getPinnedUsage());
140144
builder.humanReadableField(Fields.EVICTIONS_IN_BYTES, Fields.EVICTIONS, getEvicted());
145+
builder.humanReadableField(Fields.REMOVED_IN_BYTES, Fields.REMOVED, getRemoved());
141146
builder.field(Fields.ACTIVE_PERCENT, getActivePercent());
142147
builder.field(Fields.USED_PERCENT, getUsedPercent());
143148
builder.field(Fields.HIT_COUNT, getCacheHits());
@@ -161,6 +166,8 @@ static final class Fields {
161166
static final String PINNED_IN_BYTES = "pinned_in_bytes";
162167
static final String EVICTIONS = "evictions";
163168
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes";
169+
static final String REMOVED = "removed";
170+
static final String REMOVED_IN_BYTES = "removed_in_bytes";
164171
static final String TOTAL = "total";
165172
static final String TOTAL_IN_BYTES = "total_in_bytes";
166173

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ public AggregateFileCacheStats fileCacheStats() {
257257
overallCacheStats.usage(),
258258
overallCacheStats.pinnedUsage(),
259259
overallCacheStats.evictionWeight(),
260+
overallCacheStats.removeWeight(),
260261
overallCacheStats.hitCount(),
261262
overallCacheStats.missCount(),
262263
FileCacheStatsType.OVER_ALL_STATS
@@ -267,6 +268,7 @@ public AggregateFileCacheStats fileCacheStats() {
267268
fullFileCacheStats.usage(),
268269
fullFileCacheStats.pinnedUsage(),
269270
fullFileCacheStats.evictionWeight(),
271+
fullFileCacheStats.removeWeight(),
270272
fullFileCacheStats.hitCount(),
271273
fullFileCacheStats.missCount(),
272274
FileCacheStatsType.FULL_FILE_STATS
@@ -277,6 +279,7 @@ public AggregateFileCacheStats fileCacheStats() {
277279
blockFileCacheStats.usage(),
278280
blockFileCacheStats.pinnedUsage(),
279281
blockFileCacheStats.evictionWeight(),
282+
blockFileCacheStats.removeWeight(),
280283
blockFileCacheStats.hitCount(),
281284
blockFileCacheStats.missCount(),
282285
FileCacheStatsType.BLOCK_FILE_STATS
@@ -287,6 +290,7 @@ public AggregateFileCacheStats fileCacheStats() {
287290
pinnedFileCacheStats.usage(),
288291
pinnedFileCacheStats.pinnedUsage(),
289292
pinnedFileCacheStats.evictionWeight(),
293+
pinnedFileCacheStats.removeWeight(),
290294
pinnedFileCacheStats.hitCount(),
291295
pinnedFileCacheStats.missCount(),
292296
FileCacheStatsType.PINNED_FILE_STATS

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

Lines changed: 28 additions & 3 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;
@@ -41,6 +42,7 @@ public class FileCacheStats implements Writeable, ToXContentFragment {
4142
private final long used;
4243
private final long pinned;
4344
private final long evicted;
45+
private final long removed;
4446
private final long hits;
4547
private final long misses;
4648
private final FileCacheStatsType statsType;
@@ -52,6 +54,7 @@ public FileCacheStats(
5254
final long used,
5355
final long pinned,
5456
final long evicted,
57+
final long removed,
5558
final long hits,
5659
long misses,
5760
FileCacheStatsType statsType
@@ -61,6 +64,7 @@ public FileCacheStats(
6164
this.used = used;
6265
this.pinned = pinned;
6366
this.evicted = evicted;
67+
this.removed = removed;
6468
this.hits = hits;
6569
this.misses = misses;
6670
this.statsType = statsType;
@@ -75,7 +79,14 @@ public FileCacheStats(final StreamInput in) throws IOException {
7579
this.pinned = in.readLong();
7680
this.evicted = in.readLong();
7781
this.hits = in.readLong();
78-
this.misses = in.readLong();
82+
83+
if (in.getVersion().onOrAfter(Version.V_3_4_0)) {
84+
this.removed = in.readLong();
85+
this.misses = in.readLong();
86+
} else {
87+
this.removed = 0L;
88+
this.misses = 0L;
89+
}
7990
}
8091

8192
@Override
@@ -87,7 +98,11 @@ public void writeTo(final StreamOutput out) throws IOException {
8798
out.writeLong(pinned);
8899
out.writeLong(evicted);
89100
out.writeLong(hits);
90-
out.writeLong(misses);
101+
102+
if (out.getVersion().onOrAfter(Version.V_3_4_0)) {
103+
out.writeLong(removed);
104+
out.writeLong(misses);
105+
}
91106
}
92107

93108
public long getActive() {
@@ -102,6 +117,10 @@ public long getEvicted() {
102117
return evicted;
103118
}
104119

120+
public long getRemoved() {
121+
return removed;
122+
}
123+
105124
public long getHits() {
106125
return hits;
107126
}
@@ -136,25 +155,31 @@ static final class Fields {
136155
static final String USED = "used";
137156
static final String PINNED = "pinned";
138157
static final String USED_IN_BYTES = "used_in_bytes";
158+
static final String PINNED_IN_BYTES = "pinned_in_bytes";
139159
static final String EVICTIONS = "evictions";
140160
static final String EVICTIONS_IN_BYTES = "evictions_in_bytes";
161+
static final String REMOVED = "removed";
162+
static final String REMOVED_IN_BYTES = "removed_in_bytes";
141163
static final String ACTIVE_PERCENT = "active_percent";
142164
static final String HIT_COUNT = "hit_count";
165+
static final String MISS_COUNT = "miss_count";
143166
}
144167

145168
@Override
146169
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
147170
builder.startObject(statsType.toString());
148171
builder.humanReadableField(FileCacheStats.Fields.ACTIVE_IN_BYTES, FileCacheStats.Fields.ACTIVE, new ByteSizeValue(getActive()));
149172
builder.humanReadableField(FileCacheStats.Fields.USED_IN_BYTES, FileCacheStats.Fields.USED, new ByteSizeValue(getUsed()));
150-
builder.humanReadableField(FileCacheStats.Fields.USED_IN_BYTES, Fields.PINNED, new ByteSizeValue(getPinnedUsage()));
173+
builder.humanReadableField(FileCacheStats.Fields.PINNED_IN_BYTES, Fields.PINNED, new ByteSizeValue(getPinnedUsage()));
151174
builder.humanReadableField(
152175
FileCacheStats.Fields.EVICTIONS_IN_BYTES,
153176
FileCacheStats.Fields.EVICTIONS,
154177
new ByteSizeValue(getEvicted())
155178
);
179+
builder.humanReadableField(FileCacheStats.Fields.REMOVED_IN_BYTES, FileCacheStats.Fields.REMOVED, new ByteSizeValue(getRemoved()));
156180
builder.field(FileCacheStats.Fields.ACTIVE_PERCENT, getActivePercent());
157181
builder.field(FileCacheStats.Fields.HIT_COUNT, getHits());
182+
builder.field(FileCacheStats.Fields.MISS_COUNT, getCacheMisses());
158183
builder.endObject();
159184
return builder;
160185
}

server/src/test/java/org/opensearch/cluster/ClusterInfoTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ private static Map<String, AggregateFileCacheStats> randomFileCacheStats(int num
187187
randomLong(),
188188
randomLong(),
189189
randomLong(),
190+
randomLong(),
190191
FileCacheStatsType.OVER_ALL_STATS
191192
),
192193
new FileCacheStats(
@@ -197,6 +198,7 @@ private static Map<String, AggregateFileCacheStats> randomFileCacheStats(int num
197198
randomLong(),
198199
randomLong(),
199200
randomLong(),
201+
randomLong(),
200202
FileCacheStatsType.FULL_FILE_STATS
201203
),
202204
new FileCacheStats(
@@ -207,6 +209,7 @@ private static Map<String, AggregateFileCacheStats> randomFileCacheStats(int num
207209
randomLong(),
208210
randomLong(),
209211
randomLong(),
212+
randomLong(),
210213
FileCacheStatsType.BLOCK_FILE_STATS
211214
),
212215
new FileCacheStats(
@@ -217,6 +220,7 @@ private static Map<String, AggregateFileCacheStats> randomFileCacheStats(int num
217220
randomLong(),
218221
randomLong(),
219222
randomLong(),
223+
randomLong(),
220224
FileCacheStatsType.PINNED_FILE_STATS
221225
)
222226
);

server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,7 @@ private static AggregateFileCacheStats createAggregateFileCacheStats(long totalC
14111411
0,
14121412
0,
14131413
0,
1414+
0,
14141415
AggregateFileCacheStats.FileCacheStatsType.OVER_ALL_STATS
14151416
);
14161417
FileCacheStats fullStats = new FileCacheStats(
@@ -1421,6 +1422,7 @@ private static AggregateFileCacheStats createAggregateFileCacheStats(long totalC
14211422
0,
14221423
0,
14231424
0,
1425+
0,
14241426
AggregateFileCacheStats.FileCacheStatsType.FULL_FILE_STATS
14251427
);
14261428
FileCacheStats blockStats = new FileCacheStats(
@@ -1431,6 +1433,7 @@ private static AggregateFileCacheStats createAggregateFileCacheStats(long totalC
14311433
0,
14321434
0,
14331435
0,
1436+
0,
14341437
AggregateFileCacheStats.FileCacheStatsType.BLOCK_FILE_STATS
14351438
);
14361439
FileCacheStats pinnedStats = new FileCacheStats(
@@ -1441,6 +1444,7 @@ private static AggregateFileCacheStats createAggregateFileCacheStats(long totalC
14411444
0,
14421445
0,
14431446
0,
1447+
0,
14441448
AggregateFileCacheStats.FileCacheStatsType.PINNED_FILE_STATS
14451449
);
14461450
return new AggregateFileCacheStats(System.currentTimeMillis(), overallStats, fullStats, blockStats, pinnedStats);

server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,30 +308,30 @@ public void testDiskThresholdForRemoteShards() {
308308
"node1",
309309
new AggregateFileCacheStats(
310310
0,
311-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
312-
new FileCacheStats(0, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
313-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
314-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
311+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
312+
new FileCacheStats(0, 0, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
313+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
314+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
315315
)
316316
);
317317
fileCacheStatsMap.put(
318318
"node2",
319319
new AggregateFileCacheStats(
320320
0,
321-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
322-
new FileCacheStats(0, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
323-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
324-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
321+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
322+
new FileCacheStats(0, 0, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
323+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
324+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
325325
)
326326
);
327327
fileCacheStatsMap.put(
328328
"node3",
329329
new AggregateFileCacheStats(
330330
0,
331-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
332-
new FileCacheStats(0, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
333-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
334-
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
331+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
332+
new FileCacheStats(0, 0, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
333+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
334+
new FileCacheStats(0, 0, 1000, 0, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
335335

336336
)
337337
);

server/src/test/java/org/opensearch/cluster/routing/allocation/decider/WarmDiskThresholdDeciderTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ private Map<String, AggregateFileCacheStats> createFileCacheStatsMap(long fileCa
464464
node,
465465
new AggregateFileCacheStats(
466466
randomNonNegativeInt(),
467-
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
468-
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
469-
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
470-
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
467+
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, 0, FileCacheStatsType.OVER_ALL_STATS),
468+
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, 0, FileCacheStatsType.FULL_FILE_STATS),
469+
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, 0, FileCacheStatsType.BLOCK_FILE_STATS),
470+
new FileCacheStats(0, fileCacheSize, 0, 0, 0, 0, 0, 0, FileCacheStatsType.PINNED_FILE_STATS)
471471
)
472472
);
473473
}

server/src/test/java/org/opensearch/index/store/remote/filecache/AggregateFileCacheStatsTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public static AggregateFileCacheStats getFileCacheStats(final long fileCacheCapa
9898
stats.usage(),
9999
stats.pinnedUsage(),
100100
stats.evictionWeight(),
101+
stats.removeWeight(),
101102
stats.hitCount(),
102103
stats.missCount(),
103104
FileCacheStatsType.OVER_ALL_STATS
@@ -108,6 +109,7 @@ public static AggregateFileCacheStats getFileCacheStats(final long fileCacheCapa
108109
stats.usage(),
109110
stats.pinnedUsage(),
110111
stats.evictionWeight(),
112+
stats.removeWeight(),
111113
stats.hitCount(),
112114
stats.missCount(),
113115
FileCacheStatsType.FULL_FILE_STATS
@@ -118,6 +120,7 @@ public static AggregateFileCacheStats getFileCacheStats(final long fileCacheCapa
118120
stats.usage(),
119121
stats.pinnedUsage(),
120122
stats.evictionWeight(),
123+
stats.removeWeight(),
121124
stats.hitCount(),
122125
stats.missCount(),
123126
FileCacheStatsType.BLOCK_FILE_STATS
@@ -128,6 +131,7 @@ public static AggregateFileCacheStats getFileCacheStats(final long fileCacheCapa
128131
stats.usage(),
129132
stats.pinnedUsage(),
130133
stats.evictionWeight(),
134+
stats.removeWeight(),
131135
stats.hitCount(),
132136
stats.missCount(),
133137
FileCacheStatsType.PINNED_FILE_STATS
@@ -141,9 +145,10 @@ public static FileCacheStats getMockFullFileCacheStats() {
141145
final long used = randomLongBetween(100000, BYTES_IN_GB);
142146
final long pinned = randomLongBetween(100000, BYTES_IN_GB);
143147
final long evicted = randomLongBetween(0, getMockCacheStats().getFullFileCacheStats().evictionWeight());
148+
final long removed = randomLongBetween(0, 10);
144149
final long hit = randomLongBetween(0, 10);
145150
final long misses = randomLongBetween(0, 10);
146-
return new FileCacheStats(active, total, used, pinned, evicted, hit, misses, FileCacheStatsType.OVER_ALL_STATS);
151+
return new FileCacheStats(active, total, used, pinned, evicted, removed, hit, misses, FileCacheStatsType.OVER_ALL_STATS);
147152
}
148153

149154
public static AggregateFileCacheStats getMockFileCacheStats() throws IOException {

server/src/test/java/org/opensearch/index/store/remote/filecache/FileCacheStatsTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static FileCacheStats getMockFullFileCacheStats() {
2424
final long used = randomLongBetween(100000, BYTES_IN_GB);
2525
final long pinned = randomLongBetween(100000, BYTES_IN_GB);
2626
final long evicted = randomLongBetween(0, active);
27+
final long removed = randomLongBetween(0, 10);
2728
final long hits = randomLongBetween(0, 10);
2829
final long misses = randomLongBetween(0, 10);
2930

@@ -33,6 +34,7 @@ public static FileCacheStats getMockFullFileCacheStats() {
3334
used,
3435
pinned,
3536
evicted,
37+
removed,
3638
hits,
3739
misses,
3840
AggregateFileCacheStats.FileCacheStatsType.OVER_ALL_STATS
@@ -43,7 +45,9 @@ public static void validateFullFileCacheStats(FileCacheStats expected, FileCache
4345
assertEquals(expected.getActive(), actual.getActive());
4446
assertEquals(expected.getUsed(), actual.getUsed());
4547
assertEquals(expected.getEvicted(), actual.getEvicted());
48+
assertEquals(expected.getRemoved(), actual.getRemoved());
4649
assertEquals(expected.getHits(), actual.getHits());
50+
assertEquals(expected.getCacheMisses(), actual.getCacheMisses());
4751
assertEquals(expected.getActivePercent(), actual.getActivePercent());
4852
}
4953

0 commit comments

Comments
 (0)