Skip to content

Commit ec57e0e

Browse files
committed
Only map the non-zero values
1 parent 57d6da8 commit ec57e0e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeReq
264264
List<ShardStats> shardsStats = new ArrayList<>();
265265
for (IndexService indexService : indicesService) {
266266
for (IndexShard indexShard : indexService) {
267-
long sharedRam = shardIdToSharedRam.get(indexShard.shardId());
267+
// get the shared ram for this shard id (or zero if there's nothing in the map)
268+
long sharedRam = shardIdToSharedRam.getOrDefault(indexShard.shardId(), 0L);
268269
cancellableTask.ensureNotCancelled();
269270
if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
270271
// only report on fully started shards

server/src/main/java/org/elasticsearch/indices/IndicesQueryCache.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ public static Map<ShardId, Long> getSharedRamForAllShards(IndicesService indices
8080
indexShard.shardId(),
8181
cacheTotals
8282
);
83-
shardIdToSharedRam.put(indexShard.shardId(), sharedRam);
83+
// as a size optimization, only store non-zero values in the map
84+
if (sharedRam > 0L) {
85+
shardIdToSharedRam.put(indexShard.shardId(), sharedRam);
86+
}
8487
}
8588
}
86-
return shardIdToSharedRam;
89+
return Collections.unmodifiableMap(shardIdToSharedRam);
8790
}
8891

8992
public long getCacheSizeForShard(ShardId shardId) {

server/src/main/java/org/elasticsearch/indices/IndicesService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ static Map<Index, List<IndexShardStats>> statsByShard(final IndicesService indic
524524
final Map<Index, List<IndexShardStats>> statsByShard = new HashMap<>();
525525
for (final IndexService indexService : indicesService) {
526526
for (final IndexShard indexShard : indexService) {
527-
long sharedRam = shardIdToSharedRam.get(indexShard.shardId());
527+
// get the shared ram for this shard id (or zero if there's nothing in the map)
528+
long sharedRam = shardIdToSharedRam.getOrDefault(indexShard.shardId(), 0L);
528529
try {
529530
final IndexShardStats indexShardStats = indicesService.indexShardStats(indicesService, indexShard, flags, sharedRam);
530531
if (indexShardStats == null) {

0 commit comments

Comments
 (0)