Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for ignore_unavailable in search request #13209

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Tiered Caching] Make took time caching policy setting dynamic ([#13063](https://github.com/opensearch-project/OpenSearch/pull/13063))
- Derived fields support to derive field values at query time without indexing ([#12569](https://github.com/opensearch-project/OpenSearch/pull/12569))
- Detect breaking changes on pull requests ([#9044](https://github.com/opensearch-project/OpenSearch/pull/9044))
- Adding support for ignore_unavailable in search request ([#13209](https://github.com/opensearch-project/OpenSearch/pull/13209))
- Add cluster primary balance contraint for rebalancing with buffer ([#12656](https://github.com/opensearch-project/OpenSearch/pull/12656))
- [Remote Store] Make translog transfer timeout configurable ([#12704](https://github.com/opensearch-project/OpenSearch/pull/12704))
- Reject Resize index requests (i.e, split, shrink and clone), While DocRep to SegRep migration is in progress.([#12686](https://github.com/opensearch-project/OpenSearch/pull/12686))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
if (searchRequest.allowPartialSearchResults() != null) {
params.withAllowPartialResults(searchRequest.allowPartialSearchResults());
}
if (searchRequest.ignoreUnavailable() != null) {
params.withIgnoreUnavailable(searchRequest.ignoreUnavailable());
}
params.withBatchedReduceSize(searchRequest.getBatchedReduceSize());
if (searchRequest.scroll() != null) {
params.putParam("scroll", searchRequest.scroll().keepAlive());
Expand Down
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.ignoreUnavailable()) {
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 ignoreUnavailable;

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.ignoreUnavailable = searchRequest.ignoreUnavailable;
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)) {
ignoreUnavailable = 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(ignoreUnavailable);
}
out.writeOptionalString(localClusterAlias);
if (localClusterAlias != null) {
out.writeVLong(absoluteStartMillis);
Expand Down Expand Up @@ -567,6 +576,20 @@ public Boolean allowPartialSearchResults() {
return this.allowPartialSearchResults;
}

/**
* Sets if this request should ignore unavailable shards. This option is superseded
* by allowPartialSearchResults (ignores any type of shard failures) instead of just
* unavailable shards. (If method is not called, will default to the cluster level setting).
*/
public SearchRequest ignoreUnavailable(boolean ignoreUnavailable) {
this.ignoreUnavailable = ignoreUnavailable;
return this;
}

public Boolean ignoreUnavailable() {
return this.ignoreUnavailable;
}

/**
* 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 +770,7 @@ public boolean equals(Object o) {
&& Objects.equals(preFilterShardSize, that.preFilterShardSize)
&& Objects.equals(indicesOptions, that.indicesOptions)
&& Objects.equals(allowPartialSearchResults, that.allowPartialSearchResults)
&& Objects.equals(ignoreUnavailable, that.ignoreUnavailable)
&& Objects.equals(localClusterAlias, that.localClusterAlias)
&& absoluteStartMillis == that.absoluteStartMillis
&& ccsMinimizeRoundtrips == that.ccsMinimizeRoundtrips
Expand All @@ -770,6 +794,7 @@ public int hashCode() {
maxConcurrentShardRequests,
preFilterShardSize,
allowPartialSearchResults,
ignoreUnavailable,
localClusterAlias,
absoluteStartMillis,
ccsMinimizeRoundtrips,
Expand Down Expand Up @@ -805,6 +830,8 @@ public String toString() {
+ preFilterShardSize
+ ", allowPartialSearchResults="
+ allowPartialSearchResults
+ ", ignoreUnavailable="
+ ignoreUnavailable
+ ", localClusterAlias="
+ localClusterAlias
+ ", getOrCreateAbsoluteStartMillis="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@ public SearchRequestBuilder setAllowPartialSearchResults(boolean allowPartialSea
return this;
}

/**
* Sets if this request should ignore unavailable shards. (If method is not called,
* will default to the cluster level setting).
*/
public SearchRequestBuilder setIgnoreUnavailable(boolean ignoreUnavailable) {
request.ignoreUnavailable(ignoreUnavailable);
return this;
}

/**
* Should the query be profiled. Defaults to <code>false</code>
*/
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")) {
// only set if we have the parameter passed to override the cluster-level default
searchRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", 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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private RandomSearchRequestGenerator() {}
public static SearchRequest randomSearchRequest(Supplier<SearchSourceBuilder> randomSearchSourceBuilder) {
SearchRequest searchRequest = new SearchRequest();
searchRequest.allowPartialSearchResults(true);
searchRequest.ignoreUnavailable(randomBoolean());
if (randomBoolean()) {
searchRequest.setCcsMinimizeRoundtrips(randomBoolean());
}
Expand Down
Loading