Skip to content

Commit aa74711

Browse files
authored
Data Streams Stats action only on searchable nodes (#134737)
Relates ES-12829
1 parent e36a5d5 commit aa74711

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

modules/data-streams/src/main/java/org/elasticsearch/datastreams/action/TransportDataStreamsStatsAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected ClusterBlockException checkRequestBlock(
106106

107107
@Override
108108
protected ShardsIterator shards(ClusterState clusterState, DataStreamsStatsAction.Request request, String[] concreteIndices) {
109-
return clusterState.routingTable(projectResolver.getProjectId()).allShards(concreteIndices);
109+
return clusterState.routingTable(projectResolver.getProjectId()).allSearchableShards(concreteIndices);
110110
}
111111

112112
@Override
@@ -117,6 +117,7 @@ protected void shardOperation(
117117
ActionListener<DataStreamsStatsAction.DataStreamShardStats> listener
118118
) {
119119
ActionListener.completeWith(listener, () -> {
120+
assert shardRouting.isSearchable() : "shard routing is not searchable: " + shardRouting;
120121
IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
121122
IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
122123
StoreStats storeStats = indexShard.storeStats();

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/120_data_streams_stats.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ setup:
88
name: my-template1
99
body:
1010
index_patterns: [simple-data-stream1]
11-
template:
12-
settings:
13-
index.number_of_replicas: 0
1411
data_stream: {}
1512
- do:
1613
allowed_warnings:
@@ -19,9 +16,6 @@ setup:
1916
name: my-template2
2017
body:
2118
index_patterns: [simple-data-stream2]
22-
template:
23-
settings:
24-
index.number_of_replicas: 0
2519
data_stream: {}
2620

2721
---
@@ -51,6 +45,10 @@ setup:
5145
indices.rollover:
5246
alias: "simple-data-stream1"
5347

48+
- do:
49+
cluster.health:
50+
wait_for_no_initializing_shards: true
51+
5452
- do:
5553
indices.data_streams_stats: {}
5654
- match: { data_stream_count: 1 }
@@ -195,8 +193,8 @@ setup:
195193

196194
- do:
197195
indices.data_streams_stats: {}
198-
- match: { _shards.total: 3 }
199-
- match: { _shards.successful: 3 }
196+
- match: { _shards.total: 6 }
197+
- match: { _shards.successful: 6 }
200198
- match: { _shards.failed: 0 }
201199
- match: { data_stream_count: 2 }
202200
- match: { backing_indices: 3 }

server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ public ShardsIterator allShards(String[] indices) {
242242
return allShardsSatisfyingPredicate(indices, Predicates.always(), false);
243243
}
244244

245+
/**
246+
* Returns an iterator over all shard routing entries that are searchable (i.e., on a node that can service searches).
247+
*/
248+
public ShardsIterator allSearchableShards(String[] indices) {
249+
return allShardsSatisfyingPredicate(indices, ShardRouting::isSearchable, false);
250+
}
251+
245252
public ShardsIterator allActiveShards(String[] indices) {
246253
return allShardsSatisfyingPredicate(indices, ShardRouting::active, false);
247254
}

0 commit comments

Comments
 (0)