Skip to content

Commit

Permalink
Adding cluster setting for search ignore unavailable
Browse files Browse the repository at this point in the history
Signed-off-by: Ankit Jain <[email protected]>
  • Loading branch information
jainankitk committed Apr 17, 2024
1 parent a58f13b commit 3e5da8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,10 @@ private void executeSearch(
// No user preference defined in search request - apply cluster service default
searchRequest.allowPartialSearchResults(searchService.defaultAllowPartialSearchResults());
}
if (searchRequest.ignoreUnavailable() == null) {
// No user preference defined in search request - apply cluster service default
searchRequest.ignoreUnavailable(searchService.defaultIgnoreUnavailable());
}
if (searchRequest.isSuggestOnly()) {
// disable request cache if we have only suggest
searchRequest.requestCache(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ public void apply(Settings value, Settings current, Settings previous) {
ClusterManagerService.CLUSTER_MANAGER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
SearchService.DEFAULT_SEARCH_TIMEOUT_SETTING,
SearchService.DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS,
SearchService.DEFAULT_IGNORE_UNAVAILABLE,
TransportSearchAction.SHARD_COUNT_LIMIT_SETTING,
TransportSearchAction.SEARCH_CANCEL_AFTER_TIME_INTERVAL_SETTING,
TransportSearchAction.SEARCH_QUERY_METRICS_ENABLED_SETTING,
Expand Down
22 changes: 22 additions & 0 deletions server/src/main/java/org/opensearch/search/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
Property.NodeScope
);

// Keeping the default value to maintain existing behaviour
public static final Setting<Boolean> DEFAULT_IGNORE_UNAVAILABLE = Setting.boolSetting(
"search.default_ignore_unavailable",
false,
Property.Dynamic,
Property.NodeScope
);

public static final Setting<Integer> MAX_OPEN_SCROLL_CONTEXT = Setting.intSetting(
"search.max_open_scroll_context",
500,
Expand Down Expand Up @@ -312,6 +320,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv

private volatile boolean defaultAllowPartialSearchResults;

private volatile boolean defaultIgnoreUnavailable;

private volatile boolean lowLevelCancellation;

private volatile int maxOpenScrollContext;
Expand Down Expand Up @@ -381,6 +391,10 @@ public SearchService(
clusterService.getClusterSettings()
.addSettingsUpdateConsumer(DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS, this::setDefaultAllowPartialSearchResults);

defaultIgnoreUnavailable = DEFAULT_IGNORE_UNAVAILABLE.get(settings);
clusterService.getClusterSettings()
.addSettingsUpdateConsumer(DEFAULT_IGNORE_UNAVAILABLE, this::setDefaultIgnoreUnavailable);

maxOpenScrollContext = MAX_OPEN_SCROLL_CONTEXT.get(settings);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_OPEN_SCROLL_CONTEXT, this::setMaxOpenScrollContext);

Expand Down Expand Up @@ -453,6 +467,14 @@ public boolean defaultAllowPartialSearchResults() {
return defaultAllowPartialSearchResults;
}

private void setDefaultIgnoreUnavailable(boolean defaultIgnoreUnavailable) {
this.defaultIgnoreUnavailable = defaultIgnoreUnavailable;
}

public boolean defaultIgnoreUnavailable() {
return defaultIgnoreUnavailable;
}

private void setMaxOpenScrollContext(int maxOpenScrollContext) {
this.maxOpenScrollContext = maxOpenScrollContext;
}
Expand Down

0 comments on commit 3e5da8a

Please sign in to comment.