Sfoglia il codice sorgente

Handle nullable DocsStats and StoresStats (#109196)

Both DocsStats and StoresStats from CommonStats can be null. This PR
adds necessary checks for nullity in a few places.
Yang Wang 1 anno fa
parent
commit
f7a20ddf41

+ 5 - 0
docs/changelog/109196.yaml

@@ -0,0 +1,5 @@
+pr: 109196
+summary: Handle nullable `DocsStats` and `StoresStats`
+area: Distributed
+type: bug
+issues: []

+ 2 - 2
server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java

@@ -366,7 +366,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
                 .flatMap(Arrays::stream)
                 .filter(shard -> shard.getShardRouting().primary())
                 .map(ShardStats::getStats)
-                .mapToLong(shard -> shard.docs.getTotalSizeInBytes())
+                .mapToLong(shard -> shard.docs == null ? 0L : shard.docs.getTotalSizeInBytes())
                 .max()
                 .orElse(0);
 
@@ -376,7 +376,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction<RolloverR
                 .flatMap(Arrays::stream)
                 .filter(shard -> shard.getShardRouting().primary())
                 .map(ShardStats::getStats)
-                .mapToLong(shard -> shard.docs.getCount())
+                .mapToLong(shard -> shard.docs == null ? 0L : shard.docs.getCount())
                 .max()
                 .orElse(0);
 

+ 1 - 1
test/framework/src/main/java/org/elasticsearch/cluster/MockInternalClusterInfoService.java

@@ -108,7 +108,7 @@ public class MockInternalClusterInfoService extends InternalClusterInfoService {
             var storeStats = new StoreStats(
                 shardSizeFunctionCopy.apply(shardRouting),
                 shardSizeFunctionCopy.apply(shardRouting),
-                shardStats.getStats().store.reservedSizeInBytes()
+                shardStats.getStats().store == null ? 0L : shardStats.getStats().store.reservedSizeInBytes()
             );
             var commonStats = new CommonStats(new CommonStatsFlags(CommonStatsFlags.Flag.Store));
             commonStats.store = storeStats;

+ 5 - 2
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datatiers/NodesDataTiersUsageTransportAction.java

@@ -28,6 +28,7 @@ import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.features.NodeFeature;
+import org.elasticsearch.index.shard.DocsStats;
 import org.elasticsearch.index.store.StoreStats;
 import org.elasticsearch.indices.IndicesService;
 import org.elasticsearch.indices.NodeIndicesStats;
@@ -137,8 +138,10 @@ public class NodesDataTiersUsageTransportAction extends TransportNodesAction<
                 List<IndexShardStats> allShardStats = nodeIndicesStats.getShardStats(indexMetadata.getIndex());
                 if (allShardStats != null) {
                     for (IndexShardStats indexShardStats : allShardStats) {
-                        usageStats.incrementTotalSize(indexShardStats.getTotal().getStore().totalDataSetSizeInBytes());
-                        usageStats.incrementDocCount(indexShardStats.getTotal().getDocs().getCount());
+                        final StoreStats storeStats = indexShardStats.getTotal().getStore();
+                        usageStats.incrementTotalSize(storeStats == null ? 0L : storeStats.totalDataSetSizeInBytes());
+                        final DocsStats docsStats = indexShardStats.getTotal().getDocs();
+                        usageStats.incrementDocCount(docsStats == null ? 0L : docsStats.getCount());
 
                         ShardRouting shardRouting = routingNode.getByShardId(indexShardStats.getShardId());
                         if (shardRouting != null && shardRouting.state() == ShardRoutingState.STARTED) {

+ 4 - 1
x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/EnterpriseSearchUsageTransportAction.java

@@ -47,6 +47,7 @@ import java.util.IntSummaryStatistics;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 
 import static org.elasticsearch.xpack.core.ClientHelper.ENT_SEARCH_ORIGIN;
 import static org.elasticsearch.xpack.core.application.EnterpriseSearchFeatureSetUsage.MAX_RULE_COUNT;
@@ -175,7 +176,9 @@ public class EnterpriseSearchUsageTransportAction extends XPackUsageFeatureTrans
                     Map<String, IndexStats> indicesStats = indicesStatsResponse.getIndices();
                     int queryRulesetCount = indicesStats.values()
                         .stream()
-                        .mapToInt(indexShardStats -> (int) indexShardStats.getPrimaries().getDocs().getCount())
+                        .map(indexShardStats -> indexShardStats.getPrimaries().getDocs())
+                        .filter(Objects::nonNull)
+                        .mapToInt(docsStats -> (int) docsStats.getCount())
                         .sum();
 
                     ListQueryRulesetsAction.Request queryRulesetsCountRequest = new ListQueryRulesetsAction.Request(

+ 1 - 1
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/EmptyStateIndexRemover.java

@@ -73,7 +73,7 @@ public class EmptyStateIndexRemover implements MlDataRemover {
                         indicesStatsResponse.getIndices()
                             .values()
                             .stream()
-                            .filter(stats -> stats.getTotal().getDocs().getCount() == 0)
+                            .filter(stats -> stats.getTotal().getDocs() == null || stats.getTotal().getDocs().getCount() == 0)
                             .map(IndexStats::getIndex)
                             .collect(toSet())
                     )