Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/94164.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 94164
summary: Avoid NPE in Stateless Get/mGet
area: CRUD
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,26 @@ protected boolean resolveIndex(GetRequest request) {

@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {
ShardIterator shards = clusterService.operationRouting()
ShardIterator iterator = clusterService.operationRouting()
.getShards(
clusterService.state(),
request.concreteIndex(),
request.request().id(),
request.request().routing(),
request.request().preference()
);
if (iterator == null) {
return null;
}
// If it is stateless, only route isPromotableToPrimary shards. This is a temporary workaround until a more cohesive solution can be
// implemented for search shards.
if (DiscoveryNode.isStateless(clusterService.getSettings())) {
return new PlainShardIterator(
shards.shardId(),
shards.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
iterator.shardId(),
iterator.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
);
} else {
return shards;
return iterator;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ protected boolean resolveIndex(MultiGetShardRequest request) {

@Override
protected ShardIterator shards(ClusterState state, InternalRequest request) {
ShardIterator shards = clusterService.operationRouting()
ShardIterator iterator = clusterService.operationRouting()
.getShards(state, request.request().index(), request.request().shardId(), request.request().preference());
if (iterator == null) {
return null;
}
// If it is stateless, only route promotable shards. This is a temporary workaround until a more cohesive solution can be
// implemented for search shards.
if (DiscoveryNode.isStateless(clusterService.getSettings())) {
return new PlainShardIterator(
shards.shardId(),
shards.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
iterator.shardId(),
iterator.getShardRoutings().stream().filter(ShardRouting::isPromotableToPrimary).collect(Collectors.toList())
);
} else {
return shards;
return iterator;
}
}

Expand Down