Skip to content

Commit 1882460

Browse files
committed
add an index level engine instance, allowing to provide and share data across different shard level engines
1 parent 40fdcc4 commit 1882460

File tree

6 files changed

+161
-6
lines changed

6 files changed

+161
-6
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineModule.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.index.engine;
2121

22-
import org.elasticsearch.index.engine.robin.RobinEngineModule;
2322
import org.elasticsearch.util.guice.ModulesFactory;
2423
import org.elasticsearch.util.inject.AbstractModule;
2524
import org.elasticsearch.util.settings.Settings;
@@ -29,17 +28,13 @@
2928
*/
3029
public class EngineModule extends AbstractModule {
3130

32-
public static final class EngineSettings {
33-
public static final String ENGINE_TYPE = "index.engine.type";
34-
}
35-
3631
private final Settings settings;
3732

3833
public EngineModule(Settings settings) {
3934
this.settings = settings;
4035
}
4136

4237
@Override protected void configure() {
43-
ModulesFactory.createModule(settings.getAsClass(EngineSettings.ENGINE_TYPE, RobinEngineModule.class, "org.elasticsearch.index.engine.", "EngineModule"), settings).configure(binder());
38+
ModulesFactory.createModule(settings.getAsClass(IndexEngineModule.EngineSettings.ENGINE_TYPE, IndexEngineModule.EngineSettings.DEFAULT_ENGINE, "org.elasticsearch.index.engine.", "EngineModule"), settings).configure(binder());
4439
}
4540
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to Elastic Search and Shay Banon under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Elastic Search licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.index.engine;
21+
22+
import org.elasticsearch.index.IndexComponent;
23+
24+
/**
25+
* An "index" scoped engine that provides some meta engine for the engine, and can be used to store
26+
* index level data structures that an engine requires.
27+
*
28+
* @author kimchy (shay.banon)
29+
*/
30+
public interface IndexEngine extends IndexComponent {
31+
32+
void close();
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to Elastic Search and Shay Banon under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Elastic Search licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.index.engine;
21+
22+
import org.elasticsearch.index.engine.robin.RobinEngineModule;
23+
import org.elasticsearch.index.engine.robin.RobinIndexEngineModule;
24+
import org.elasticsearch.util.inject.AbstractModule;
25+
import org.elasticsearch.util.inject.Module;
26+
import org.elasticsearch.util.settings.Settings;
27+
28+
import static org.elasticsearch.util.guice.ModulesFactory.*;
29+
30+
/**
31+
* @author kimchy (shay.banon)
32+
*/
33+
public class IndexEngineModule extends AbstractModule {
34+
35+
public static final class EngineSettings {
36+
public static final String ENGINE_TYPE = "index.engine.type";
37+
public static final Class<? extends Module> DEFAULT_INDEX_ENGINE = RobinIndexEngineModule.class;
38+
public static final Class<? extends Module> DEFAULT_ENGINE = RobinEngineModule.class;
39+
}
40+
41+
private final Settings settings;
42+
43+
public IndexEngineModule(Settings settings) {
44+
this.settings = settings;
45+
}
46+
47+
@Override protected void configure() {
48+
createModule(settings.getAsClass(EngineSettings.ENGINE_TYPE, EngineSettings.DEFAULT_INDEX_ENGINE, "org.elasticsearch.index.engine.", "IndexEngineModule"), settings).configure(binder());
49+
}
50+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to Elastic Search and Shay Banon under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Elastic Search licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.index.engine.robin;
21+
22+
import org.elasticsearch.index.AbstractIndexComponent;
23+
import org.elasticsearch.index.Index;
24+
import org.elasticsearch.index.engine.IndexEngine;
25+
import org.elasticsearch.index.settings.IndexSettings;
26+
import org.elasticsearch.util.inject.Inject;
27+
import org.elasticsearch.util.settings.Settings;
28+
29+
/**
30+
* @author kimchy (shay.banon)
31+
*/
32+
public class RobinIndexEngine extends AbstractIndexComponent implements IndexEngine {
33+
34+
@Inject public RobinIndexEngine(Index index, @IndexSettings Settings indexSettings) {
35+
super(index, indexSettings);
36+
}
37+
38+
@Override public void close() {
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to Elastic Search and Shay Banon under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Elastic Search licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.index.engine.robin;
21+
22+
import org.elasticsearch.index.engine.IndexEngine;
23+
import org.elasticsearch.util.inject.AbstractModule;
24+
25+
/**
26+
* @author kimchy (shay.banon)
27+
*/
28+
public class RobinIndexEngineModule extends AbstractModule {
29+
30+
@Override protected void configure() {
31+
bind(IndexEngine.class).to(RobinIndexEngine.class).asEagerSingleton();
32+
}
33+
}

modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.elasticsearch.index.analysis.AnalysisService;
2929
import org.elasticsearch.index.cache.IndexCacheModule;
3030
import org.elasticsearch.index.cache.filter.FilterCache;
31+
import org.elasticsearch.index.engine.IndexEngine;
32+
import org.elasticsearch.index.engine.IndexEngineModule;
3133
import org.elasticsearch.index.gateway.IndexGateway;
3234
import org.elasticsearch.index.gateway.IndexGatewayModule;
3335
import org.elasticsearch.index.mapper.MapperServiceModule;
@@ -174,6 +176,7 @@ public synchronized IndexService createIndex(String sIndexName, Settings setting
174176
modules.add(new LocalNodeIdModule(localNodeId));
175177
modules.add(new IndexSettingsModule(indexSettings));
176178
modules.add(new IndicesPluginsModule(indexSettings, pluginsService));
179+
modules.add(new IndexEngineModule(indexSettings));
177180
modules.add(new AnalysisModule(indexSettings));
178181
modules.add(new SimilarityModule(indexSettings));
179182
modules.add(new IndexCacheModule(indexSettings));
@@ -228,6 +231,7 @@ private synchronized void deleteIndex(String index, boolean delete) throws Elast
228231

229232
indexInjector.getInstance(FilterCache.class).close();
230233
indexInjector.getInstance(AnalysisService.class).close();
234+
indexInjector.getInstance(IndexEngine.class).close();
231235
indexInjector.getInstance(IndexServiceManagement.class).close();
232236

233237
indexInjector.getInstance(IndexGateway.class).close(delete);

0 commit comments

Comments
 (0)