Skip to content

Commit acfe562

Browse files
committed
Made resolveIndices() in TransportSingleShardAction exception-safe
Originally, the resolveIndices() method of TransportSingleShardAction was implemented with concreteSingleIndex(), which however can throw exceptions for validation issues. As throwing exceptions is not suitable for the intended meta-data use, this was moved to concreteResolvedIndices(). This MIGHT return a super-set of the indices of concreteSingleIndex() when the latter would throw an exception. This is for the intended purposes of resolveIndices() however acceptable. Signed-off-by: Nils Bandener <nils.bandener@eliatra.com>
1 parent 1a13466 commit acfe562

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

server/src/main/java/org/opensearch/action/support/single/shard/TransportSingleShardAction.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ protected void resolveRequest(ClusterState state, InternalRequest request) {
160160

161161
@Override
162162
public ResolvedIndices resolveIndices(Request request) {
163-
return ResolvedIndices.ofNonNull(resolveToConcreteSingleIndex(request, clusterService.state()));
163+
if (resolveIndex(request)) {
164+
// We do not use resolveToConcreteSingleIndex() here because it might throw exceptions for validation errors.
165+
// Instead, we use indexNameExpressionResolver.concreteResolvedIndices(), which allows us to retrieve
166+
// index names without validation errors. This is potentially a super-set of the indices resolved in
167+
// resolveToConcreteSingleIndex(), but this is only a hypothetical state. In practise, we should
168+
// also always get one element here. If for some reason that's not the case, the code will hit the
169+
// validation error when executing the action.
170+
return ResolvedIndices.of(indexNameExpressionResolver.concreteResolvedIndices(clusterService.state(), request));
171+
} else {
172+
return ResolvedIndices.of(request.index());
173+
}
164174
}
165175

166176
private String resolveToConcreteSingleIndex(Request request, ClusterState clusterState) {

0 commit comments

Comments
 (0)