Skip to content

Commit

Permalink
Adding support for ignore_unavailable_shards in search request
Browse files Browse the repository at this point in the history
Signed-off-by: Ankit Jain <[email protected]>
  • Loading branch information
jainankitk committed Apr 16, 2024
1 parent 8d9e12d commit a12dd35
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,10 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha
currentPhase.getName()
);
}
onPhaseFailure(currentPhase, "Partial shards failure (" + discrepancy + " shards unavailable)", null);
return;
if (!request.getIgnoreUnavailableShards()) {
onPhaseFailure(currentPhase, "Partial shards failure (" + discrepancy + " shards unavailable)", null);
return;
}
}
}
if (logger.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class SearchRequest extends ActionRequest implements IndicesRequest.Repla

private Boolean allowPartialSearchResults;

private Boolean ignoreUnavailableShards;

private Scroll scroll;

private int batchedReduceSize = DEFAULT_BATCHED_REDUCE_SIZE;
Expand Down Expand Up @@ -198,6 +200,7 @@ private SearchRequest(
boolean finalReduce
) {
this.allowPartialSearchResults = searchRequest.allowPartialSearchResults;
this.ignoreUnavailableShards = searchRequest.ignoreUnavailableShards;
this.batchedReduceSize = searchRequest.batchedReduceSize;
this.ccsMinimizeRoundtrips = searchRequest.ccsMinimizeRoundtrips;
this.indices = indices;
Expand Down Expand Up @@ -246,6 +249,9 @@ public SearchRequest(StreamInput in) throws IOException {
maxConcurrentShardRequests = in.readVInt();
preFilterShardSize = in.readOptionalVInt();
allowPartialSearchResults = in.readOptionalBoolean();
if (in.getVersion().onOrAfter(Version.V_2_14_0)) {
ignoreUnavailableShards = in.readOptionalBoolean();
}
localClusterAlias = in.readOptionalString();
if (localClusterAlias != null) {
absoluteStartMillis = in.readVLong();
Expand Down Expand Up @@ -283,6 +289,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(maxConcurrentShardRequests);
out.writeOptionalVInt(preFilterShardSize);
out.writeOptionalBoolean(allowPartialSearchResults);
if (out.getVersion().onOrAfter(Version.V_2_14_0)) {
out.writeOptionalBoolean(ignoreUnavailableShards);
}
out.writeOptionalString(localClusterAlias);
if (localClusterAlias != null) {
out.writeVLong(absoluteStartMillis);
Expand Down Expand Up @@ -567,6 +576,15 @@ public Boolean allowPartialSearchResults() {
return this.allowPartialSearchResults;
}

public SearchRequest ignoreUnavailableShards(boolean ignoreUnavailableShards) {
this.ignoreUnavailableShards = ignoreUnavailableShards;
return this;
}

public Boolean getIgnoreUnavailableShards() {
return this.ignoreUnavailableShards;
}

/**
* Sets the number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection
* mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large.
Expand Down Expand Up @@ -747,6 +765,7 @@ public boolean equals(Object o) {
&& Objects.equals(preFilterShardSize, that.preFilterShardSize)
&& Objects.equals(indicesOptions, that.indicesOptions)
&& Objects.equals(allowPartialSearchResults, that.allowPartialSearchResults)
&& Objects.equals(ignoreUnavailableShards, that.ignoreUnavailableShards)
&& Objects.equals(localClusterAlias, that.localClusterAlias)
&& absoluteStartMillis == that.absoluteStartMillis
&& ccsMinimizeRoundtrips == that.ccsMinimizeRoundtrips
Expand All @@ -770,6 +789,7 @@ public int hashCode() {
maxConcurrentShardRequests,
preFilterShardSize,
allowPartialSearchResults,
ignoreUnavailableShards,
localClusterAlias,
absoluteStartMillis,
ccsMinimizeRoundtrips,
Expand Down Expand Up @@ -805,6 +825,8 @@ public String toString() {
+ preFilterShardSize
+ ", allowPartialSearchResults="
+ allowPartialSearchResults
+ ", ignoreUnavailableShards="
+ ignoreUnavailableShards
+ ", localClusterAlias="
+ localClusterAlias
+ ", getOrCreateAbsoluteStartMillis="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public static void parseSearchRequest(
searchRequest.allowPartialSearchResults(request.paramAsBoolean("allow_partial_search_results", null));
}

if (request.hasParam("ignore_unavailable_shards")) {
// only set if we have the parameter passed to override the cluster-level default
searchRequest.ignoreUnavailableShards(request.paramAsBoolean("ignore_unavailable_shards", null));
}

if (request.hasParam("phase_took")) {
// only set if we have the parameter passed to override the cluster-level default
// else phaseTook = null
Expand Down

0 comments on commit a12dd35

Please sign in to comment.