-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add EngineConfig extensions to EnginePlugin #1387
Merged
nknize
merged 4 commits into
opensearch-project:main
from
nknize:enginePlugin/EngineConfigFactory
Oct 20, 2021
Merged
Changes from 3 commits
Commits
Show all changes
4 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 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 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 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
127 changes: 127 additions & 0 deletions
127
server/src/main/java/org/opensearch/index/engine/EngineConfigFactory.java
This file contains 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,127 @@ | ||
/* | ||
* 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.index.engine; | ||
|
||
import org.apache.lucene.analysis.Analyzer; | ||
import org.apache.lucene.index.MergePolicy; | ||
import org.apache.lucene.search.QueryCache; | ||
import org.apache.lucene.search.QueryCachingPolicy; | ||
import org.apache.lucene.search.ReferenceManager; | ||
import org.apache.lucene.search.Sort; | ||
import org.apache.lucene.search.similarities.Similarity; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.index.codec.CodecService; | ||
import org.opensearch.index.seqno.RetentionLeases; | ||
import org.opensearch.index.shard.ShardId; | ||
import org.opensearch.index.store.Store; | ||
import org.opensearch.index.translog.TranslogConfig; | ||
import org.opensearch.indices.breaker.CircuitBreakerService; | ||
import org.opensearch.plugins.EnginePlugin; | ||
import org.opensearch.plugins.PluginsService; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* A factory to create an EngineConfig based on custom plugin overrides | ||
*/ | ||
public class EngineConfigFactory { | ||
private final Optional<CodecService> codecService; | ||
|
||
/** default ctor primarily used for tests without plugins */ | ||
public EngineConfigFactory(IndexSettings idxSettings) { | ||
this(Collections.emptyList(), idxSettings); | ||
} | ||
|
||
/** | ||
* Construct a factory using the plugin service and provided index settings | ||
*/ | ||
public EngineConfigFactory(PluginsService pluginsService, IndexSettings idxSettings) { | ||
this(pluginsService.filterPlugins(EnginePlugin.class), idxSettings); | ||
} | ||
|
||
/* private constructor to construct the factory from specific EnginePlugins and IndexSettings */ | ||
EngineConfigFactory(Collection<EnginePlugin> enginePlugins, IndexSettings idxSettings) { | ||
setiah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Optional<CodecService> codecService = Optional.empty(); | ||
String codecServiceOverridingPlugin = null; | ||
for (EnginePlugin enginePlugin : enginePlugins) { | ||
// get overriding codec service from EnginePlugin | ||
if (codecService.isPresent() == false) { | ||
codecService = enginePlugin.getCustomCodecService(idxSettings); | ||
codecServiceOverridingPlugin = enginePlugin.getClass().getName(); | ||
} else { | ||
throw new IllegalStateException( | ||
"existing codec service already overridden in: " | ||
+ codecServiceOverridingPlugin | ||
+ " attempting to override again by: " | ||
+ enginePlugin.getClass().getName() | ||
); | ||
} | ||
} | ||
this.codecService = codecService; | ||
} | ||
|
||
/** Insantiates a new EngineConfig from the provided custom overrides */ | ||
public EngineConfig newEngineConfig( | ||
ShardId shardId, | ||
ThreadPool threadPool, | ||
IndexSettings indexSettings, | ||
Engine.Warmer warmer, | ||
Store store, | ||
MergePolicy mergePolicy, | ||
Analyzer analyzer, | ||
Similarity similarity, | ||
CodecService codecService, | ||
Engine.EventListener eventListener, | ||
QueryCache queryCache, | ||
QueryCachingPolicy queryCachingPolicy, | ||
TranslogConfig translogConfig, | ||
TimeValue flushMergesAfter, | ||
List<ReferenceManager.RefreshListener> externalRefreshListener, | ||
List<ReferenceManager.RefreshListener> internalRefreshListener, | ||
Sort indexSort, | ||
CircuitBreakerService circuitBreakerService, | ||
LongSupplier globalCheckpointSupplier, | ||
Supplier<RetentionLeases> retentionLeasesSupplier, | ||
LongSupplier primaryTermSupplier, | ||
EngineConfig.TombstoneDocSupplier tombstoneDocSupplier | ||
) { | ||
|
||
return new EngineConfig( | ||
shardId, | ||
threadPool, | ||
indexSettings, | ||
warmer, | ||
store, | ||
mergePolicy, | ||
analyzer, | ||
similarity, | ||
this.codecService.isPresent() == true ? this.codecService.get() : codecService, | ||
eventListener, | ||
queryCache, | ||
queryCachingPolicy, | ||
translogConfig, | ||
flushMergesAfter, | ||
externalRefreshListener, | ||
internalRefreshListener, | ||
indexSort, | ||
circuitBreakerService, | ||
globalCheckpointSupplier, | ||
retentionLeasesSupplier, | ||
primaryTermSupplier, | ||
tombstoneDocSupplier | ||
); | ||
} | ||
} |
This file contains 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 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be declared with Optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was mostly for the logic on L111.
this.codecService.isPresent() ? this.codecService.get() : codecService;
instead of
this.codecService != null ? this.codecService : codecService;
Which feels a little clumsy?