From 396cf117c9b77b0b88750c474893b2d89e663d0e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 17 Feb 2015 10:33:39 +0100 Subject: [PATCH] Simplify setting index.store.type with smb_simple_fs and smb_mmap_fs This commit changes work done in #60 by using automatic store type discovery which exists in elasticsearch core. Instead of writing configuration like: ```yaml index.store.type: org.elasticsearch.index.store.fs.SmbMmapFsIndexStoreModule index.store.type: org.elasticsearch.index.store.fs.SmbSimpleFsIndexStoreModule ``` We can now use: ```yaml index.store.type: smb_mmap_fs index.store.type: smb_simple_fs ``` Note that we move `org.elasticsearch.index.store.fs.SmbMmapFsIndexStoreModule` to `org.elasticsearch.index.store.smbmmapfs.SmbMmapFsIndexStoreModule` and `org.elasticsearch.index.store.fs.SmbSimpleFsDirectoryService` to `org.elasticsearch.index.store.smbsimplefs.SmbSimpleFsDirectoryService` instead of deprecating the old classes and add new ones. It means that if users were using a 2.5.2-SNAPSHOT version, they will need to update their settings. (cherry picked from commit 613ce5a) (cherry picked from commit 7831521) --- README.md | 20 +++++---- .../SmbMmapFsDirectoryService.java | 3 +- .../SmbMmapFsIndexStore.java | 2 +- .../SmbMmapFsIndexStoreModule.java | 2 +- .../SmbSimpleFsDirectoryService.java | 3 +- .../SmbSimpleFsIndexStore.java | 2 +- .../SmbSimpleFsIndexStoreModule.java | 2 +- .../index/store/AbstractAzureFsTest.java | 42 +++++++++++++++++++ .../index/store/SmbMMapFsTest.java | 36 ++++++++++++++++ .../index/store/SmbSimpleFsTest.java | 34 +++++++++++++++ 10 files changed, 131 insertions(+), 15 deletions(-) rename src/main/java/org/elasticsearch/index/store/{fs => smbmmapfs}/SmbMmapFsDirectoryService.java (94%) rename src/main/java/org/elasticsearch/index/store/{fs => smbmmapfs}/SmbMmapFsIndexStore.java (97%) rename src/main/java/org/elasticsearch/index/store/{fs => smbmmapfs}/SmbMmapFsIndexStoreModule.java (95%) rename src/main/java/org/elasticsearch/index/store/{fs => smbsimplefs}/SmbSimpleFsDirectoryService.java (94%) rename src/main/java/org/elasticsearch/index/store/{fs => smbsimplefs}/SmbSimpleFsIndexStore.java (97%) rename src/main/java/org/elasticsearch/index/store/{fs => smbsimplefs}/SmbSimpleFsIndexStoreModule.java (95%) create mode 100644 src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java create mode 100644 src/test/java/org/elasticsearch/index/store/SmbMMapFsTest.java create mode 100644 src/test/java/org/elasticsearch/index/store/SmbSimpleFsTest.java diff --git a/README.md b/README.md index 6719e6e23bb..edb37903be6 100644 --- a/README.md +++ b/README.md @@ -453,24 +453,26 @@ When using a shared file system based on the SMB protocol (like Azure File Servi The Azure Cloud plugin provides two storage types optimized for SMB: -- `org.elasticsearch.index.store.fs.SmbMmapFsIndexStoreModule`: a SMB specific implementation of the default [mmap fs](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-store.html#mmapfs) -- `org.elasticsearch.index.store.fs.SmbSimpleFsIndexStoreModule`: a SMB specific implementation of the default [simple fs](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-store.html#simplefs) +- `smb_mmap_fs`: a SMB specific implementation of the default [mmap fs](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-store.html#mmapfs) +- `smb_simple_fs`: a SMB specific implementation of the default [simple fs](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-store.html#simplefs) -To use one of these specific storage types, you need to install the Azure Cloud plugin and restart the node. Then configure Elasticsearch to set -the storage type you want. +To use one of these specific storage types, you need to install the Azure Cloud plugin and restart the node. +Then configure Elasticsearch to set the storage type you want. -This can be configured for all indices by adding this to the config/elasticsearch.yml file: -``` -index.store.type: org.elasticsearch.index.store.fs.SmbSimpleFsIndexStoreModule +This can be configured for all indices by adding this to the `elasticsearch.yml` file: + +```yaml +index.store.type: smb_simple_fs ``` Note that setting will be applied for newly created indices. It can also be set on a per-index basis at index creation time: -``` + +```sh curl -XPUT localhost:9200/my_index -d '{ "settings": { - "index.store.type": "org.elasticsearch.index.store.fs.SmbMmapFsIndexStoreModule" + "index.store.type": "smb_mmap_fs" } }' ``` diff --git a/src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsDirectoryService.java b/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java similarity index 94% rename from src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsDirectoryService.java rename to src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java index cbdfb3f527d..9db1800658d 100644 --- a/src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsDirectoryService.java +++ b/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsDirectoryService.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.store.fs; +package org.elasticsearch.index.store.smbmmapfs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; @@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.IndexStore; +import org.elasticsearch.index.store.fs.FsDirectoryService; import java.io.IOException; import java.nio.file.Path; diff --git a/src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsIndexStore.java b/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java similarity index 97% rename from src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsIndexStore.java rename to src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java index 76a7a04310c..e6df91c7738 100644 --- a/src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsIndexStore.java +++ b/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStore.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.store.fs; +package org.elasticsearch.index.store.smbmmapfs; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; diff --git a/src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsIndexStoreModule.java b/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStoreModule.java similarity index 95% rename from src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsIndexStoreModule.java rename to src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStoreModule.java index 768fab5c0db..335a58b32c5 100644 --- a/src/main/java/org/elasticsearch/index/store/fs/SmbMmapFsIndexStoreModule.java +++ b/src/main/java/org/elasticsearch/index/store/smbmmapfs/SmbMmapFsIndexStoreModule.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.store.fs; +package org.elasticsearch.index.store.smbmmapfs; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.store.IndexStore; diff --git a/src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsDirectoryService.java b/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java similarity index 94% rename from src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsDirectoryService.java rename to src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java index 61020bc1ef3..af4c4702b5c 100644 --- a/src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsDirectoryService.java +++ b/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsDirectoryService.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.store.fs; +package org.elasticsearch.index.store.smbsimplefs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; @@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.IndexStore; +import org.elasticsearch.index.store.fs.FsDirectoryService; import java.io.IOException; import java.nio.file.Path; diff --git a/src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsIndexStore.java b/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java similarity index 97% rename from src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsIndexStore.java rename to src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java index bd3a5ad539b..54f25b89199 100644 --- a/src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsIndexStore.java +++ b/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStore.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.store.fs; +package org.elasticsearch.index.store.smbsimplefs; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; diff --git a/src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsIndexStoreModule.java b/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStoreModule.java similarity index 95% rename from src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsIndexStoreModule.java rename to src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStoreModule.java index 88d075ab77b..9604dc11c77 100644 --- a/src/main/java/org/elasticsearch/index/store/fs/SmbSimpleFsIndexStoreModule.java +++ b/src/main/java/org/elasticsearch/index/store/smbsimplefs/SmbSimpleFsIndexStoreModule.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.store.fs; +package org.elasticsearch.index.store.smbsimplefs; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.index.store.IndexStore; diff --git a/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java b/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java new file mode 100644 index 00000000000..497e807d60e --- /dev/null +++ b/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch 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.store; + +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.junit.Test; + +import static org.hamcrest.Matchers.is; + +abstract public class AbstractAzureFsTest extends ElasticsearchIntegrationTest { + + @Test + public void testAzureFs() { + // Create an index and index some documents + createIndex("test"); + long nbDocs = randomIntBetween(10, 1000); + for (long i = 0; i < nbDocs; i++) { + index("test", "doc", "" + i, "foo", "bar"); + } + refresh(); + SearchResponse response = client().prepareSearch("test").get(); + assertThat(response.getHits().totalHits(), is(nbDocs)); + } +} diff --git a/src/test/java/org/elasticsearch/index/store/SmbMMapFsTest.java b/src/test/java/org/elasticsearch/index/store/SmbMMapFsTest.java new file mode 100644 index 00000000000..ec4941cb24d --- /dev/null +++ b/src/test/java/org/elasticsearch/index/store/SmbMMapFsTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch 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.store; + +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; + + +public class SmbMMapFsTest extends AbstractAzureFsTest { + + @Override + public Settings indexSettings() { + return ImmutableSettings.builder() + .put(super.indexSettings()) + .put("index.store.type", "smb_mmap_fs") + .build(); + } + +} diff --git a/src/test/java/org/elasticsearch/index/store/SmbSimpleFsTest.java b/src/test/java/org/elasticsearch/index/store/SmbSimpleFsTest.java new file mode 100644 index 00000000000..96c55a42562 --- /dev/null +++ b/src/test/java/org/elasticsearch/index/store/SmbSimpleFsTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch 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.store; + +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; + + +public class SmbSimpleFsTest extends AbstractAzureFsTest { + @Override + public Settings indexSettings() { + return ImmutableSettings.builder() + .put(super.indexSettings()) + .put("index.store.type", "smb_simple_fs") + .build(); + } +}