From 18824606454c65443ce481d649ed330d26cbc9ac Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 19 May 2010 04:24:39 +0300 Subject: [PATCH] add an index level engine instance, allowing to provide and share data across different shard level engines --- .../index/engine/EngineModule.java | 7 +-- .../index/engine/IndexEngine.java | 33 ++++++++++++ .../index/engine/IndexEngineModule.java | 50 +++++++++++++++++++ .../index/engine/robin/RobinIndexEngine.java | 40 +++++++++++++++ .../engine/robin/RobinIndexEngineModule.java | 33 ++++++++++++ .../indices/InternalIndicesService.java | 4 ++ 6 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngine.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngineModule.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngine.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngineModule.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineModule.java index a8957d49885..2170591569e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/EngineModule.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.engine; -import org.elasticsearch.index.engine.robin.RobinEngineModule; import org.elasticsearch.util.guice.ModulesFactory; import org.elasticsearch.util.inject.AbstractModule; import org.elasticsearch.util.settings.Settings; @@ -29,10 +28,6 @@ import org.elasticsearch.util.settings.Settings; */ public class EngineModule extends AbstractModule { - public static final class EngineSettings { - public static final String ENGINE_TYPE = "index.engine.type"; - } - private final Settings settings; public EngineModule(Settings settings) { @@ -40,6 +35,6 @@ public class EngineModule extends AbstractModule { } @Override protected void configure() { - ModulesFactory.createModule(settings.getAsClass(EngineSettings.ENGINE_TYPE, RobinEngineModule.class, "org.elasticsearch.index.engine.", "EngineModule"), settings).configure(binder()); + ModulesFactory.createModule(settings.getAsClass(IndexEngineModule.EngineSettings.ENGINE_TYPE, IndexEngineModule.EngineSettings.DEFAULT_ENGINE, "org.elasticsearch.index.engine.", "EngineModule"), settings).configure(binder()); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngine.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngine.java new file mode 100644 index 00000000000..25e98e81e4a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngine.java @@ -0,0 +1,33 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.engine; + +import org.elasticsearch.index.IndexComponent; + +/** + * An "index" scoped engine that provides some meta engine for the engine, and can be used to store + * index level data structures that an engine requires. + * + * @author kimchy (shay.banon) + */ +public interface IndexEngine extends IndexComponent { + + void close(); +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngineModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngineModule.java new file mode 100644 index 00000000000..b5a5113f5fc --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/IndexEngineModule.java @@ -0,0 +1,50 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.engine; + +import org.elasticsearch.index.engine.robin.RobinEngineModule; +import org.elasticsearch.index.engine.robin.RobinIndexEngineModule; +import org.elasticsearch.util.inject.AbstractModule; +import org.elasticsearch.util.inject.Module; +import org.elasticsearch.util.settings.Settings; + +import static org.elasticsearch.util.guice.ModulesFactory.*; + +/** + * @author kimchy (shay.banon) + */ +public class IndexEngineModule extends AbstractModule { + + public static final class EngineSettings { + public static final String ENGINE_TYPE = "index.engine.type"; + public static final Class DEFAULT_INDEX_ENGINE = RobinIndexEngineModule.class; + public static final Class DEFAULT_ENGINE = RobinEngineModule.class; + } + + private final Settings settings; + + public IndexEngineModule(Settings settings) { + this.settings = settings; + } + + @Override protected void configure() { + createModule(settings.getAsClass(EngineSettings.ENGINE_TYPE, EngineSettings.DEFAULT_INDEX_ENGINE, "org.elasticsearch.index.engine.", "IndexEngineModule"), settings).configure(binder()); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngine.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngine.java new file mode 100644 index 00000000000..773f69b76b6 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngine.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.engine.robin; + +import org.elasticsearch.index.AbstractIndexComponent; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.engine.IndexEngine; +import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.util.inject.Inject; +import org.elasticsearch.util.settings.Settings; + +/** + * @author kimchy (shay.banon) + */ +public class RobinIndexEngine extends AbstractIndexComponent implements IndexEngine { + + @Inject public RobinIndexEngine(Index index, @IndexSettings Settings indexSettings) { + super(index, indexSettings); + } + + @Override public void close() { + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngineModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngineModule.java new file mode 100644 index 00000000000..562636346ac --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinIndexEngineModule.java @@ -0,0 +1,33 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.engine.robin; + +import org.elasticsearch.index.engine.IndexEngine; +import org.elasticsearch.util.inject.AbstractModule; + +/** + * @author kimchy (shay.banon) + */ +public class RobinIndexEngineModule extends AbstractModule { + + @Override protected void configure() { + bind(IndexEngine.class).to(RobinIndexEngine.class).asEagerSingleton(); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index a19c52b3ec9..dc7a8bf2272 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -28,6 +28,8 @@ import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.IndexCacheModule; import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.engine.IndexEngine; +import org.elasticsearch.index.engine.IndexEngineModule; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.IndexGatewayModule; import org.elasticsearch.index.mapper.MapperServiceModule; @@ -174,6 +176,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent