-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add dynamic index and cluster setting for concurrent segment search #7956
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
server/src/main/java/org/opensearch/search/query/QueryPhaseSearcherWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.search.query; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.lucene.search.Query; | ||
| import org.opensearch.common.util.FeatureFlags; | ||
| import org.opensearch.search.aggregations.AggregationProcessor; | ||
| import org.opensearch.search.internal.ContextIndexSearcher; | ||
| import org.opensearch.search.internal.SearchContext; | ||
| import org.apache.lucene.search.CollectorManager; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.LinkedList; | ||
|
|
||
| /** | ||
| * Wrapper class for QueryPhaseSearcher that handles path selection for concurrent vs | ||
| * non-concurrent search query phase and aggregation processor. | ||
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class QueryPhaseSearcherWrapper implements QueryPhaseSearcher { | ||
| private static final Logger LOGGER = LogManager.getLogger(QueryPhaseSearcherWrapper.class); | ||
| private final QueryPhaseSearcher defaultQueryPhaseSearcher; | ||
| private final QueryPhaseSearcher concurrentQueryPhaseSearcher; | ||
|
|
||
| public QueryPhaseSearcherWrapper() { | ||
| this.defaultQueryPhaseSearcher = new QueryPhase.DefaultQueryPhaseSearcher(); | ||
| this.concurrentQueryPhaseSearcher = FeatureFlags.isEnabled(FeatureFlags.CONCURRENT_SEGMENT_SEARCH) | ||
| ? new ConcurrentQueryPhaseSearcher() | ||
| : null; | ||
| } | ||
|
|
||
| /** | ||
| * Perform search using {@link CollectorManager} | ||
| * | ||
| * @param searchContext search context | ||
| * @param searcher context index searcher | ||
| * @param query query | ||
| * @param hasTimeout "true" if timeout was set, "false" otherwise | ||
| * @return is rescoring required or not | ||
| * @throws java.io.IOException IOException | ||
| */ | ||
| @Override | ||
| public boolean searchWith( | ||
| SearchContext searchContext, | ||
| ContextIndexSearcher searcher, | ||
| Query query, | ||
| LinkedList<QueryCollectorContext> collectors, | ||
| boolean hasFilterCollector, | ||
| boolean hasTimeout | ||
| ) throws IOException { | ||
| if (searchContext.isConcurrentSegmentSearchEnabled()) { | ||
| LOGGER.info("Using concurrent search over segments (experimental)"); | ||
| return concurrentQueryPhaseSearcher.searchWith(searchContext, searcher, query, collectors, hasFilterCollector, hasTimeout); | ||
| } else { | ||
| return defaultQueryPhaseSearcher.searchWith(searchContext, searcher, query, collectors, hasFilterCollector, hasTimeout); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * {@link AggregationProcessor} to use to setup and post process aggregation related collectors during search request | ||
| * @param searchContext search context | ||
| * @return {@link AggregationProcessor} to use | ||
| */ | ||
| @Override | ||
| public AggregationProcessor aggregationProcessor(SearchContext searchContext) { | ||
| if (searchContext.isConcurrentSegmentSearchEnabled()) { | ||
| LOGGER.info("Using concurrent search over segments (experimental)"); | ||
| return concurrentQueryPhaseSearcher.aggregationProcessor(searchContext); | ||
| } else { | ||
| return defaultQueryPhaseSearcher.aggregationProcessor(searchContext); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,8 @@ | |
| import org.opensearch.common.settings.Setting.Property; | ||
| import org.hamcrest.Matchers; | ||
| import org.opensearch.common.util.FeatureFlags; | ||
| import org.opensearch.index.IndexSettings; | ||
| import org.opensearch.search.SearchService; | ||
| import org.opensearch.test.FeatureFlagSetter; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
@@ -282,4 +284,55 @@ public void testDynamicIndexSettingsRegistration() { | |
| () -> module.registerDynamicSetting(Setting.floatSetting("index.custom.setting2", 1.0f, Property.IndexScope)) | ||
| ); | ||
| } | ||
|
|
||
| public void testConcurrentSegmentSearchClusterSettings() { | ||
| // Test that we throw an exception without the feature flag | ||
| Settings settings = Settings.builder().put(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), true).build(); | ||
| SettingsException ex = expectThrows(SettingsException.class, () -> new SettingsModule(settings)); | ||
| assertEquals( | ||
| "unknown setting [" | ||
| + SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey() | ||
| + "] please check that any required plugins are installed, or check the breaking " | ||
| + "changes documentation for removed settings", | ||
| ex.getMessage() | ||
| ); | ||
|
|
||
| // Test that the settings updates correctly with the feature flag | ||
| FeatureFlagSetter.set(FeatureFlags.CONCURRENT_SEGMENT_SEARCH); | ||
| boolean settingValue = randomBoolean(); | ||
| Settings settingsWithFeatureFlag = Settings.builder() | ||
| .put(SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), settingValue) | ||
| .build(); | ||
| SettingsModule settingsModule = new SettingsModule(settingsWithFeatureFlag); | ||
| assertEquals(settingValue, SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.get(settingsModule.getSettings())); | ||
| } | ||
|
|
||
| public void testConcurrentSegmentSearchIndexSettings() { | ||
| Settings.Builder target = Settings.builder().put(Settings.EMPTY); | ||
| Settings.Builder update = Settings.builder(); | ||
|
|
||
| // Test that we throw an exception without the feature flag | ||
| SettingsModule module = new SettingsModule(Settings.EMPTY); | ||
| IndexScopedSettings indexScopedSettings = module.getIndexScopedSettings(); | ||
| expectThrows( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an |
||
| SettingsException.class, | ||
| () -> indexScopedSettings.updateDynamicSettings( | ||
| Settings.builder().put(IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), true).build(), | ||
| target, | ||
| update, | ||
| "node" | ||
| ) | ||
| ); | ||
|
|
||
| // Test that the settings updates correctly with the feature flag | ||
| FeatureFlagSetter.set(FeatureFlags.CONCURRENT_SEGMENT_SEARCH); | ||
| SettingsModule moduleWithFeatureFlag = new SettingsModule(Settings.EMPTY); | ||
| IndexScopedSettings indexScopedSettingsWithFeatureFlag = moduleWithFeatureFlag.getIndexScopedSettings(); | ||
| indexScopedSettingsWithFeatureFlag.updateDynamicSettings( | ||
| Settings.builder().put(IndexSettings.INDEX_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), true).build(), | ||
| target, | ||
| update, | ||
| "node" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.