Skip to content

Commit

Permalink
Rename shardId to shardOrdinal for clarity
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Froh <froh@amazon.com>
  • Loading branch information
msfroh committed Dec 19, 2024
1 parent c7abf62 commit f29e111
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ public int hashCode() {
return Objects.hash(this.field, this.id, this.max);
}

public boolean shardMatches(int shardId, int numShards) {
public boolean shardMatches(int shardOrdinal, int numShards) {
if (max >= numShards) {
// Slices are distributed over shards
return id % numShards == shardId;
return id % numShards == shardOrdinal;
}
// Shards are distributed over slices
return shardId % max == id;
return shardOrdinal % max == id;
}

/**
Expand All @@ -234,7 +234,7 @@ public Query toFilter(ClusterService clusterService, ShardSearchRequest request,
throw new IllegalArgumentException("field " + field + " not found");
}

int shardId = request.shardId().id();
int shardOrdinal = request.shardId().id();
int numShards = context.getIndexSettings().getNumberOfShards();
if ((request.preference() != null || request.indexRoutings().length > 0)) {
GroupShardsIterator<ShardIterator> group = buildShardIterator(clusterService, request);
Expand All @@ -250,21 +250,21 @@ public Query toFilter(ClusterService clusterService, ShardSearchRequest request,
*/
numShards = group.size();
int ord = 0;
shardId = -1;
shardOrdinal = -1;
// remap the original shard id with its index (position) in the sorted shard iterator.
for (ShardIterator it : group) {
assert it.shardId().getIndex().equals(request.shardId().getIndex());
if (request.shardId().equals(it.shardId())) {
shardId = ord;
shardOrdinal = ord;
break;
}
++ord;
}
assert shardId != -1 : "shard id: " + request.shardId().getId() + " not found in index shard routing";
assert shardOrdinal != -1 : "shard id: " + request.shardId().getId() + " not found in index shard routing";
}
}

if (shardMatches(shardId, numShards) == false) {
if (shardMatches(shardOrdinal, numShards) == false) {
// We should have already excluded this shard before routing to it.
// If we somehow land here, then we match nothing.
return new MatchNoDocsQuery("this shard is not part of the slice");
Expand Down

0 comments on commit f29e111

Please sign in to comment.