Skip to content

Commit 6e2f3ec

Browse files
committed
Remove engine factory provider
This commit removes a level of indirection by removing the engine factory provider abstraction.
1 parent ce7e52e commit 6e2f3ec

File tree

5 files changed

+33
-51
lines changed

5 files changed

+33
-51
lines changed

core/src/main/java/org/elasticsearch/indices/IndicesService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public class IndicesService extends AbstractLifecycleComponent
177177
private final IndicesRequestCache indicesRequestCache;
178178
private final IndicesQueryCache indicesQueryCache;
179179
private final MetaStateService metaStateService;
180-
private final Collection<Tuple<EnginePlugin, EnginePlugin.EngineFactoryProvider>> engineFactoryProviders;
180+
private final Collection<EnginePlugin> enginePlugins;
181181

182182
@Override
183183
protected void doStart() {
@@ -190,7 +190,7 @@ public IndicesService(Settings settings, PluginsService pluginsService, NodeEnvi
190190
MapperRegistry mapperRegistry, NamedWriteableRegistry namedWriteableRegistry, ThreadPool threadPool,
191191
IndexScopedSettings indexScopedSettings, CircuitBreakerService circuitBreakerService, BigArrays bigArrays,
192192
ScriptService scriptService, Client client, MetaStateService metaStateService,
193-
Collection<Tuple<EnginePlugin, EnginePlugin.EngineFactoryProvider>> engineFactoryProviders) {
193+
Collection<EnginePlugin> enginePlugins) {
194194
super(settings);
195195
this.threadPool = threadPool;
196196
this.pluginsService = pluginsService;
@@ -221,7 +221,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon
221221
this.cleanInterval = INDICES_CACHE_CLEAN_INTERVAL_SETTING.get(settings);
222222
this.cacheCleaner = new CacheCleaner(indicesFieldDataCache, indicesRequestCache, logger, threadPool, this.cleanInterval);
223223
this.metaStateService = metaStateService;
224-
this.engineFactoryProviders = engineFactoryProviders;
224+
this.enginePlugins = enginePlugins;
225225
}
226226

227227
@Override
@@ -474,9 +474,9 @@ private synchronized IndexService createIndexService(final String reason,
474474

475475
private EngineFactory getEngineFactory(final IndexSettings idxSettings) {
476476
final List<Tuple<EnginePlugin, Optional<EngineFactory>>> engineFactories =
477-
engineFactoryProviders
477+
enginePlugins
478478
.stream()
479-
.map(p -> Tuple.tuple(p.v1(), p.v2().apply(idxSettings)))
479+
.map(p -> Tuple.tuple(p, p.getMaybeEngineFactory(idxSettings)))
480480
.filter(t -> Objects.requireNonNull(t.v2()).isPresent())
481481
.collect(Collectors.toList());
482482
if (engineFactories.isEmpty()) {

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import org.elasticsearch.cluster.routing.allocation.DiskThresholdMonitor;
5757
import org.elasticsearch.cluster.service.ClusterService;
5858
import org.elasticsearch.common.StopWatch;
59-
import org.elasticsearch.common.collect.Tuple;
6059
import org.elasticsearch.common.component.Lifecycle;
6160
import org.elasticsearch.common.component.LifecycleComponent;
6261
import org.elasticsearch.common.inject.Binder;
@@ -389,18 +388,13 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
389388
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment, xContentRegistry);
390389

391390
// collect engine factory providers per plugin
392-
final Collection<Tuple<EnginePlugin, EnginePlugin.EngineFactoryProvider>> engineFactoryProviders =
393-
pluginsService
394-
.filterPlugins(EnginePlugin.class)
395-
.stream()
396-
.map(p -> Tuple.tuple(p, p.getEngineFactoryProvider()))
397-
.collect(Collectors.toList());
391+
final Collection<EnginePlugin> enginePlugins = pluginsService.filterPlugins(EnginePlugin.class);
398392

399393
final IndicesService indicesService =
400394
new IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry, analysisModule.getAnalysisRegistry(),
401395
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
402396
threadPool, settingsModule.getIndexScopedSettings(), circuitBreakerService, bigArrays,
403-
scriptModule.getScriptService(), client, metaStateService, engineFactoryProviders);
397+
scriptModule.getScriptService(), client, metaStateService, enginePlugins);
404398

405399
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
406400
.flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService,

core/src/main/java/org/elasticsearch/plugins/EnginePlugin.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,20 @@
2323
import org.elasticsearch.index.engine.EngineFactory;
2424

2525
import java.util.Optional;
26-
import java.util.function.Function;
2726

2827
/**
2928
* A plugin that provides alternative engine implementations.
3029
*/
3130
public interface EnginePlugin {
3231

33-
/**
34-
* An engine factory provider. When an index is created this method is invoked for each engine plugin. Engine plugins can inspect the
35-
* index settings to determine whether or not to provide an engine factory for the given index. A plugin that is not overriding the
36-
* default engine should return {@link Optional#empty()}. If multiple plugins return an engine factory for a given index the index will
37-
* not be created and an {@link IllegalStateException} will be thrown during index creation.
38-
*/
39-
@FunctionalInterface
40-
interface EngineFactoryProvider extends Function<IndexSettings, Optional<EngineFactory>> {
41-
42-
}
43-
44-
/**
45-
* The engine factory provider for this engine plugin.
46-
*
47-
* @return the engine factory provider
48-
*/
49-
EngineFactoryProvider getEngineFactoryProvider();
32+
/**
33+
* When an index is created this method is invoked for each engine plugin. Engine plugins can inspect the index settings to determine
34+
* whether or not to provide an engine factory for the given index. A plugin that is not overriding the default engine should return
35+
* {@link Optional#empty()}. If multiple plugins return an engine factory for a given index the index will not be created and an
36+
* {@link IllegalStateException} will be thrown during index creation.
37+
*
38+
* @return an optional engine factory
39+
*/
40+
Optional<EngineFactory> getMaybeEngineFactory(final IndexSettings indexSettings);
5041

5142
}

core/src/test/java/org/elasticsearch/indices/IndicesServiceTests.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,12 @@ public List<Setting<?>> getSettings() {
126126
}
127127

128128
@Override
129-
public EngineFactoryProvider getEngineFactoryProvider() {
130-
return indexSettings -> {
131-
if (FOO_INDEX_SETTING.get(indexSettings.getSettings())) {
132-
return Optional.of(new FooEngineFactory());
133-
} else {
134-
return Optional.empty();
135-
}
136-
};
129+
public Optional<EngineFactory> getMaybeEngineFactory(final IndexSettings indexSettings) {
130+
if (FOO_INDEX_SETTING.get(indexSettings.getSettings())) {
131+
return Optional.of(new FooEngineFactory());
132+
} else {
133+
return Optional.empty();
134+
}
137135
}
138136

139137
}
@@ -158,14 +156,12 @@ public List<Setting<?>> getSettings() {
158156
}
159157

160158
@Override
161-
public EngineFactoryProvider getEngineFactoryProvider() {
162-
return indexSettings -> {
163-
if (BAR_INDEX_SETTING.get(indexSettings.getSettings())) {
164-
return Optional.of(new BarEngineFactory());
165-
} else {
166-
return Optional.empty();
167-
}
168-
};
159+
public Optional<EngineFactory> getMaybeEngineFactory(final IndexSettings indexSettings) {
160+
if (BAR_INDEX_SETTING.get(indexSettings.getSettings())) {
161+
return Optional.of(new BarEngineFactory());
162+
} else {
163+
return Optional.empty();
164+
}
169165
}
170166

171167
}
@@ -508,7 +504,7 @@ public void testStatsByShardDoesNotDieFromExpectedExceptions() {
508504
assertThat("unexpected shard stats", indexStats.get(index), equalTo(shardStats));
509505
}
510506

511-
public void testEngineFactoryProvider() throws IOException {
507+
public void testGetEngineFactory() throws IOException {
512508
final IndicesService indicesService = getIndicesService();
513509

514510
final Boolean[] values = new Boolean[] { true, false, null };
@@ -536,7 +532,7 @@ public void testEngineFactoryProvider() throws IOException {
536532
}
537533
}
538534

539-
public void testConflictingEngineFactoryProviders() throws IOException {
535+
public void testConflictingEngineFactories() throws IOException {
540536
final String indexName = "foobar";
541537
final Index index = new Index(indexName, UUIDs.randomBase64UUID());
542538
final Settings settings = Settings.builder()

test/framework/src/main/java/org/elasticsearch/index/MockEngineFactoryPlugin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.lucene.index.AssertingDirectoryReader;
2222
import org.apache.lucene.index.FilterDirectoryReader;
2323
import org.elasticsearch.common.settings.Setting;
24+
import org.elasticsearch.index.engine.EngineFactory;
2425
import org.elasticsearch.plugins.EnginePlugin;
2526
import org.elasticsearch.plugins.Plugin;
2627
import org.elasticsearch.test.engine.MockEngineFactory;
@@ -43,8 +44,8 @@ public List<Setting<?>> getSettings() {
4344
}
4445

4546
@Override
46-
public EngineFactoryProvider getEngineFactoryProvider() {
47-
return indexSettings -> Optional.of(new MockEngineFactory(getReaderWrapperClass()));
47+
public Optional<EngineFactory> getMaybeEngineFactory(final IndexSettings indexSettings) {
48+
return Optional.of(new MockEngineFactory(getReaderWrapperClass()));
4849
}
4950

5051
protected Class<? extends FilterDirectoryReader> getReaderWrapperClass() {

0 commit comments

Comments
 (0)