Skip to content

Commit 2984734

Browse files
authored
Simplify number of shards setting (#30783)
This is code that was leftover from the move to one shard by default. Here in index metadata we were preserving the default number of shards settings independently of the area of code where we set this value on an index that does not explicitly have an number of shards setting. This took into consideration the es.index.max_number_of_shards system property, and was used in search requests to set the default maximum number of concurrent shard requests. We set the default there based on the default number of shards so that in a one-node case a search request could concurrently hit all shards on an index with the defaults. Now that we default to one shard, we expect fewer shards in clusters and this adjustment of the node count as the max number of concurrent shard requests is no longer needed. This commit then changes the default number of shards settings to be consistent with the value used when an index is created, and removes the now unneeded adjustment in search requests.
1 parent a17d6ca commit 2984734

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,12 @@ private void executeSearch(SearchTask task, SearchTimeProvider timeProvider, Sea
341341
return searchTransportService.getConnection(clusterName, discoveryNode);
342342
};
343343
if (searchRequest.isMaxConcurrentShardRequestsSet() == false) {
344-
// we try to set a default of max concurrent shard requests based on
345-
// the node count but upper-bound it by 256 by default to keep it sane. A single
346-
// search request that fans out lots of shards should hit a cluster too hard while 256 is already a lot.
347-
// we multiply it by the default number of shards such that a single request in a cluster of 1 would hit all shards of a
348-
// default index.
349-
searchRequest.setMaxConcurrentShardRequests(Math.min(256, nodeCount
350-
* IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getDefault(Settings.EMPTY)));
344+
/*
345+
* We try to set a default of max concurrent shard requests based on the node count but upper-bound it by 256 by default to keep
346+
* it sane. A single search request that fans out to lots of shards should not hit a cluster too hard while 256 is already a
347+
* lot.
348+
*/
349+
searchRequest.setMaxConcurrentShardRequests(Math.min(256, nodeCount));
351350
}
352351
boolean preFilterSearchShards = shouldPreFilterSearchShards(searchRequest, shardIterators);
353352
searchAsyncAction(task, searchRequest, shardIterators, timeProvider, connectionLookup, clusterState.version(),

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ static Setting<Integer> buildNumberOfShardsSetting() {
181181
if (maxNumShards < 1) {
182182
throw new IllegalArgumentException("es.index.max_number_of_shards must be > 0");
183183
}
184-
return Setting.intSetting(SETTING_NUMBER_OF_SHARDS, Math.min(5, maxNumShards), 1, maxNumShards,
185-
Property.IndexScope, Property.Final);
184+
return Setting.intSetting(SETTING_NUMBER_OF_SHARDS, 1, 1, maxNumShards, Property.IndexScope, Property.Final);
186185
}
187186

188187
public static final String INDEX_SETTING_PREFIX = "index.";

0 commit comments

Comments
 (0)