Skip to content

Commit dc05aaa

Browse files
committed
Add comment explaining slice <-> shard assignment
Signed-off-by: Michael Froh <[email protected]>
1 parent 2a6d593 commit dc05aaa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server/src/main/java/org/opensearch/cluster/routing/OperationRouting.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ public GroupShardsIterator<ShardIterator> searchShards(
289289
if (slice != null) {
290290
// Filter the returned shards for the given slice
291291
CollectionUtil.timSort(indexIterators);
292+
// We use the ordinal of the iterator in the group (after sorting) rather than the shard id, because
293+
// computeTargetedShards may return a subset of shards for an index, if a routing parameter was
294+
// specified. In that case, the set of routable shards is considered the full universe of available
295+
// shards for each index, when mapping shards to slices. If no routing parameter was specified,
296+
// then ordinals and shard IDs are the same. This mimics the logic in
297+
// org.opensearch.search.slice.SliceBuilder.toFilter.
292298
for (int i = 0; i < indexIterators.size(); i++) {
293299
if (slice.shardMatches(i, indexIterators.size())) {
294300
allShardIterators.add(indexIterators.get(i));

0 commit comments

Comments
 (0)