-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EngineConfig extensions to EnginePlugin (#1387)
This commit adds an extension point to EngineConfig through EnginePlugin using a new EngineConfigFactory mechanism. EnginePlugin provides interface methods to override configurations in EngineConfig. The EngineConfigFactory produces a new instance of the EngineConfig using these overrides. Defaults are used absent overridden configurations. This serves as a mechanism to override Engine configurations (e.g., CodecService, TranslogConfig) enabling Plugins to have higher fidelity for changing Engine behavior without having to override the entire Engine (which is only permitted for a single plugin). Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
- Loading branch information
Showing
15 changed files
with
208 additions
and
9 deletions.
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) { | ||
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.