add index level store constuct (on top of the shard level store)

This commit is contained in:
kimchy 2010-06-23 07:47:18 +03:00
parent 265780fa17
commit 3b4584040b
24 changed files with 485 additions and 146 deletions

View File

@ -12,6 +12,7 @@
<w>blobstore</w>
<w>bool</w>
<w>booleans</w>
<w>bytebuffer</w>
<w>cacheable</w>
<w>camelcase</w>
<w>canonicalhost</w>

View File

@ -29,9 +29,7 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.fs.MmapFsStore;
import org.elasticsearch.index.store.fs.NioFsStore;
import org.elasticsearch.index.store.fs.SimpleFsStore;
import org.elasticsearch.index.store.fs.*;
import org.elasticsearch.index.store.memory.ByteBufferStore;
import org.elasticsearch.index.store.memory.HeapStore;
import org.elasticsearch.index.store.ram.RamStore;
@ -271,11 +269,11 @@ public class SimpleStoreBenchmark {
if (type.equalsIgnoreCase("ram")) {
store = new RamStore(shardId, settings);
} else if (type.equalsIgnoreCase("simple-fs")) {
store = new SimpleFsStore(shardId, settings, environment, localNodeId);
store = new SimpleFsStore(shardId, settings, new SimpleFsIndexStore(shardId.index(), settings, environment, localNodeId));
} else if (type.equalsIgnoreCase("mmap-fs")) {
store = new NioFsStore(shardId, settings, environment, localNodeId);
store = new NioFsStore(shardId, settings, new NioFsIndexStore(shardId.index(), settings, environment, localNodeId));
} else if (type.equalsIgnoreCase("nio-fs")) {
store = new MmapFsStore(shardId, settings, environment, localNodeId);
store = new MmapFsStore(shardId, settings, new MmapFsIndexStore(shardId.index(), settings, environment, localNodeId));
} else if (type.equalsIgnoreCase("memory-direct")) {
Settings byteBufferSettings = settingsBuilder()
.put(settings)

View File

@ -53,6 +53,7 @@ import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.recovery.RecoveryAction;
import org.elasticsearch.index.shard.service.IndexShard;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.StoreModule;
import org.elasticsearch.index.translog.TranslogModule;
@ -211,7 +212,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde
List<Module> modules = Lists.newArrayList();
modules.add(new ShardsPluginsModule(indexSettings, pluginsService));
modules.add(new IndexShardModule(shardId));
modules.add(new StoreModule(indexSettings));
modules.add(new StoreModule(indexSettings, injector.getInstance(IndexStore.class)));
modules.add(new DeletionPolicyModule(indexSettings));
modules.add(new MergePolicyModule(indexSettings));
modules.add(new MergeSchedulerModule(indexSettings));

View File

@ -0,0 +1,35 @@
/*
* 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.store;
import org.elasticsearch.index.IndexComponent;
/**
* @author kimchy (shay.banon)
*/
public interface IndexStore extends IndexComponent {
/**
* Is the store a persistent store that can survive full restarts.
*/
boolean persistent();
Class<? extends Store> shardStoreClass();
}

View File

@ -0,0 +1,67 @@
/*
* 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.store;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesFactory;
import org.elasticsearch.common.os.OsUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.store.fs.MmapFsIndexStoreModule;
import org.elasticsearch.index.store.fs.NioFsIndexStoreModule;
import org.elasticsearch.index.store.fs.SimpleFsIndexStoreModule;
import org.elasticsearch.index.store.memory.MemoryIndexStoreModule;
import org.elasticsearch.index.store.ram.RamIndexStoreModule;
/**
* @author kimchy (Shay Banon)
*/
public class IndexStoreModule extends AbstractModule {
private final Settings settings;
public IndexStoreModule(Settings settings) {
this.settings = settings;
}
@Override protected void configure() {
Class<? extends Module> indexStoreModule = NioFsIndexStoreModule.class;
if (OsUtils.WINDOWS) {
indexStoreModule = SimpleFsIndexStoreModule.class;
}
String storeType = settings.get("index.store.type");
if ("ram".equalsIgnoreCase(storeType)) {
indexStoreModule = RamIndexStoreModule.class;
} else if ("memory".equalsIgnoreCase(storeType)) {
indexStoreModule = MemoryIndexStoreModule.class;
} else if ("fs".equalsIgnoreCase(storeType)) {
// nothing to set here ... (we default to fs)
} else if ("simplefs".equalsIgnoreCase(storeType) || "simple_fs".equals(storeType)) {
indexStoreModule = SimpleFsIndexStoreModule.class;
} else if ("niofs".equalsIgnoreCase(storeType) || "nio_fs".equalsIgnoreCase(storeType)) {
indexStoreModule = NioFsIndexStoreModule.class;
} else if ("mmapfs".equalsIgnoreCase(storeType) || "mmap_fs".equalsIgnoreCase(storeType)) {
indexStoreModule = MmapFsIndexStoreModule.class;
} else if (storeType != null) {
indexStoreModule = settings.getAsClass("index.store.type", indexStoreModule, "org.elasticsearch.index.store.", "IndexStoreModule");
}
ModulesFactory.createModule(indexStoreModule, settings).configure(binder());
}
}

View File

@ -20,15 +20,7 @@
package org.elasticsearch.index.store;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesFactory;
import org.elasticsearch.common.os.OsUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.store.fs.MmapFsStoreModule;
import org.elasticsearch.index.store.fs.NioFsStoreModule;
import org.elasticsearch.index.store.fs.SimpleFsStoreModule;
import org.elasticsearch.index.store.memory.MemoryStoreModule;
import org.elasticsearch.index.store.ram.RamStoreModule;
/**
* @author kimchy (Shay Banon)
@ -37,32 +29,15 @@ public class StoreModule extends AbstractModule {
private final Settings settings;
public StoreModule(Settings settings) {
private final IndexStore indexStore;
public StoreModule(Settings settings, IndexStore indexStore) {
this.indexStore = indexStore;
this.settings = settings;
}
@Override protected void configure() {
Class<? extends Module> storeModule = NioFsStoreModule.class;
if (OsUtils.WINDOWS) {
storeModule = SimpleFsStoreModule.class;
}
String storeType = settings.get("index.store.type");
if ("ram".equalsIgnoreCase(storeType)) {
storeModule = RamStoreModule.class;
} else if ("memory".equalsIgnoreCase(storeType)) {
storeModule = MemoryStoreModule.class;
} else if ("fs".equalsIgnoreCase(storeType)) {
// nothing to set here ... (we default to fs)
} else if ("simplefs".equalsIgnoreCase(storeType) || "simple_fs".equals(storeType)) {
storeModule = SimpleFsStoreModule.class;
} else if ("niofs".equalsIgnoreCase(storeType) || "nio_fs".equalsIgnoreCase(storeType)) {
storeModule = NioFsStoreModule.class;
} else if ("mmapfs".equalsIgnoreCase(storeType) || "mmap_fs".equalsIgnoreCase(storeType)) {
storeModule = MmapFsStoreModule.class;
} else if (storeType != null) {
storeModule = settings.getAsClass("index.store.type", storeModule, "org.elasticsearch.index.store.", "StoreModule");
}
ModulesFactory.createModule(storeModule, settings).configure(binder());
bind(Store.class).to(indexStore.shardStoreClass()).asEagerSingleton();
bind(StoreManagement.class).asEagerSingleton();
}
}

View File

@ -0,0 +1,66 @@
/*
* 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.store.fs;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.IndexStore;
import java.io.File;
/**
* @author kimchy (shay.banon)
*/
public abstract class FsIndexStore extends AbstractIndexComponent implements IndexStore {
private final File location;
public FsIndexStore(Index index, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) {
super(index, indexSettings);
this.location = new File(new File(new File(environment.workWithClusterFile(), "indices"), localNodeId), index.name());
if (!location.exists()) {
boolean result = false;
for (int i = 0; i < 5; i++) {
result = location.mkdirs();
if (result) {
break;
}
}
}
}
@Override public boolean persistent() {
return true;
}
public File location() {
return location;
}
public File shardLocation(ShardId shardId) {
return new File(new File(location, Integer.toString(shardId.id())), "index");
}
}

View File

@ -38,9 +38,9 @@ import java.io.IOException;
/**
* @author kimchy (shay.banon)
*/
public abstract class AbstractFsStore<T extends Directory> extends AbstractStore<T> {
public abstract class FsStore<T extends Directory> extends AbstractStore<T> {
public AbstractFsStore(ShardId shardId, @IndexSettings Settings indexSettings) {
public FsStore(ShardId shardId, @IndexSettings Settings indexSettings) {
super(shardId, indexSettings);
}

View File

@ -1,64 +0,0 @@
/*
* 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.store.fs;
import org.elasticsearch.index.shard.ShardId;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
*/
public class FsStores {
public static final String DEFAULT_INDICES_LOCATION = "indices";
public static final String MAIN_INDEX_SUFFIX = "index";
public static synchronized File createStoreFilePath(File basePath, String localNodeId, ShardId shardId, @Nullable String suffix) throws IOException {
// TODO we need to clean the nodeId from invalid folder characters
File f = new File(new File(basePath, DEFAULT_INDICES_LOCATION), localNodeId);
f = new File(f, shardId.index().name());
f = new File(f, Integer.toString(shardId.id()));
if (suffix != null) {
f = new File(f, suffix);
}
if (f.exists() && f.isDirectory()) {
return f;
}
boolean result = false;
for (int i = 0; i < 5; i++) {
result = f.mkdirs();
if (result) {
break;
}
}
if (!result) {
if (f.exists() && f.isDirectory()) {
return f;
}
throw new IOException("Failed to create directories for [" + f + "]");
}
return f;
}
}

View File

@ -0,0 +1,42 @@
/*
* 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.store.fs;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.store.Store;
/**
* @author kimchy (shay.banon)
*/
public class MmapFsIndexStore extends FsIndexStore {
@Inject public MmapFsIndexStore(Index index, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) {
super(index, indexSettings, environment, localNodeId);
}
@Override public Class<? extends Store> shardStoreClass() {
return MmapFsStore.class;
}
}

View File

@ -20,14 +20,14 @@
package org.elasticsearch.index.store.fs;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.IndexStore;
/**
* @author kimchy (Shay Banon)
*/
public class SimpleFsStoreModule extends AbstractModule {
public class MmapFsIndexStoreModule extends AbstractModule {
@Override protected void configure() {
bind(Store.class).to(SimpleFsStore.class).asEagerSingleton();
bind(IndexStore.class).to(MmapFsIndexStore.class).asEagerSingleton();
}
}

View File

@ -23,21 +23,18 @@ import org.apache.lucene.store.*;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.store.SwitchDirectory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.support.ForceSyncDirectory;
import java.io.File;
import java.io.IOException;
import static org.elasticsearch.index.store.fs.FsStores.*;
/**
* @author kimchy (shay.banon)
*/
public class MmapFsStore extends AbstractFsStore<Directory> {
public class MmapFsStore extends FsStore<Directory> {
private final boolean syncToDisk;
@ -47,7 +44,7 @@ public class MmapFsStore extends AbstractFsStore<Directory> {
private final boolean suggestUseCompoundFile;
@Inject public MmapFsStore(ShardId shardId, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) throws IOException {
@Inject public MmapFsStore(ShardId shardId, @IndexSettings Settings indexSettings, IndexStore indexStore) throws IOException {
super(shardId, indexSettings);
// by default, we don't need to sync to disk, since we use the gateway
this.syncToDisk = componentSettings.getAsBoolean("sync_to_disk", false);
@ -58,7 +55,8 @@ public class MmapFsStore extends AbstractFsStore<Directory> {
} else if (fsLock.equals("simple")) {
lockFactory = new SimpleFSLockFactory();
}
this.fsDirectory = new CustomMMapDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), lockFactory, syncToDisk);
File location = ((FsIndexStore) indexStore).shardLocation(shardId);
this.fsDirectory = new CustomMMapDirectory(location, lockFactory, syncToDisk);
SwitchDirectory switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory);
if (switchDirectory != null) {

View File

@ -0,0 +1,42 @@
/*
* 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.store.fs;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.store.Store;
/**
* @author kimchy (shay.banon)
*/
public class NioFsIndexStore extends FsIndexStore {
@Inject public NioFsIndexStore(Index index, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) {
super(index, indexSettings, environment, localNodeId);
}
@Override public Class<? extends Store> shardStoreClass() {
return NioFsStore.class;
}
}

View File

@ -20,14 +20,14 @@
package org.elasticsearch.index.store.fs;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.IndexStore;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class MmapFsStoreModule extends AbstractModule {
public class NioFsIndexStoreModule extends AbstractModule {
@Override protected void configure() {
bind(Store.class).to(MmapFsStore.class).asEagerSingleton();
bind(IndexStore.class).to(NioFsIndexStore.class).asEagerSingleton();
}
}

View File

@ -23,21 +23,18 @@ import org.apache.lucene.store.*;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.store.SwitchDirectory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.support.ForceSyncDirectory;
import java.io.File;
import java.io.IOException;
import static org.elasticsearch.index.store.fs.FsStores.*;
/**
* @author kimchy (Shay Banon)
*/
public class NioFsStore extends AbstractFsStore<Directory> {
public class NioFsStore extends FsStore<Directory> {
private final boolean syncToDisk;
@ -47,7 +44,7 @@ public class NioFsStore extends AbstractFsStore<Directory> {
private final boolean suggestUseCompoundFile;
@Inject public NioFsStore(ShardId shardId, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) throws IOException {
@Inject public NioFsStore(ShardId shardId, @IndexSettings Settings indexSettings, IndexStore indexStore) throws IOException {
super(shardId, indexSettings);
// by default, we don't need to sync to disk, since we use the gateway
this.syncToDisk = componentSettings.getAsBoolean("sync_to_disk", false);
@ -58,7 +55,8 @@ public class NioFsStore extends AbstractFsStore<Directory> {
} else if (fsLock.equals("simple")) {
lockFactory = new SimpleFSLockFactory();
}
this.fsDirectory = new CustomNioFSDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), lockFactory, syncToDisk);
File location = ((FsIndexStore) indexStore).shardLocation(shardId);
this.fsDirectory = new CustomNioFSDirectory(location, lockFactory, syncToDisk);
SwitchDirectory switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory);
if (switchDirectory != null) {

View File

@ -0,0 +1,42 @@
/*
* 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.store.fs;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.store.Store;
/**
* @author kimchy (shay.banon)
*/
public class SimpleFsIndexStore extends FsIndexStore {
@Inject public SimpleFsIndexStore(Index index, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) {
super(index, indexSettings, environment, localNodeId);
}
@Override public Class<? extends Store> shardStoreClass() {
return SimpleFsStore.class;
}
}

View File

@ -20,14 +20,14 @@
package org.elasticsearch.index.store.fs;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.IndexStore;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class NioFsStoreModule extends AbstractModule {
public class SimpleFsIndexStoreModule extends AbstractModule {
@Override protected void configure() {
bind(Store.class).to(NioFsStore.class).asEagerSingleton();
bind(IndexStore.class).to(SimpleFsIndexStore.class).asEagerSingleton();
}
}

View File

@ -23,21 +23,18 @@ import org.apache.lucene.store.*;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.store.SwitchDirectory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.LocalNodeId;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.support.ForceSyncDirectory;
import java.io.File;
import java.io.IOException;
import static org.elasticsearch.index.store.fs.FsStores.*;
/**
* @author kimchy (Shay Banon)
*/
public class SimpleFsStore extends AbstractFsStore<Directory> {
public class SimpleFsStore extends FsStore<Directory> {
private final boolean syncToDisk;
@ -47,7 +44,7 @@ public class SimpleFsStore extends AbstractFsStore<Directory> {
private final boolean suggestUseCompoundFile;
@Inject public SimpleFsStore(ShardId shardId, @IndexSettings Settings indexSettings, Environment environment, @LocalNodeId String localNodeId) throws IOException {
@Inject public SimpleFsStore(ShardId shardId, @IndexSettings Settings indexSettings, IndexStore indexStore) throws IOException {
super(shardId, indexSettings);
// by default, we don't need to sync to disk, since we use the gateway
this.syncToDisk = componentSettings.getAsBoolean("sync_to_disk", false);
@ -58,7 +55,8 @@ public class SimpleFsStore extends AbstractFsStore<Directory> {
} else if (fsLock.equals("simple")) {
lockFactory = new SimpleFSLockFactory();
}
this.fsDirectory = new CustomSimpleFSDirectory(createStoreFilePath(environment.workWithClusterFile(), localNodeId, shardId, MAIN_INDEX_SUFFIX), lockFactory, syncToDisk);
File location = ((FsIndexStore) indexStore).shardLocation(shardId);
this.fsDirectory = new CustomSimpleFSDirectory(location, lockFactory, syncToDisk);
SwitchDirectory switchDirectory = buildSwitchDirectoryIfNeeded(fsDirectory);
if (switchDirectory != null) {

View File

@ -0,0 +1,46 @@
/*
* 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.store.memory;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.Store;
/**
* @author kimchy (shay.banon)
*/
public class ByteBufferIndexStore extends AbstractIndexComponent implements IndexStore {
@Inject public ByteBufferIndexStore(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings);
}
@Override public boolean persistent() {
return false;
}
@Override public Class<? extends Store> shardStoreClass() {
return ByteBufferStore.class;
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.store.memory;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.Store;
/**
* @author kimchy (shay.banon)
*/
public class HeapIndexStore extends AbstractIndexComponent implements IndexStore {
@Inject public HeapIndexStore(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings);
}
@Override public boolean persistent() {
return false;
}
@Override public Class<? extends Store> shardStoreClass() {
return HeapStore.class;
}
}

View File

@ -22,25 +22,25 @@ package org.elasticsearch.index.store.memory;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.IndexStore;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class MemoryStoreModule extends AbstractModule {
public class MemoryIndexStoreModule extends AbstractModule {
private final Settings settings;
public MemoryStoreModule(Settings settings) {
public MemoryIndexStoreModule(Settings settings) {
this.settings = settings;
}
@Override protected void configure() {
String location = settings.get("index.store.memory.location", "direct");
if ("direct".equalsIgnoreCase(location)) {
bind(Store.class).to(ByteBufferStore.class).asEagerSingleton();
bind(IndexStore.class).to(ByteBufferIndexStore.class).asEagerSingleton();
} else if ("heap".equalsIgnoreCase(location)) {
bind(Store.class).to(HeapStore.class).asEagerSingleton();
bind(IndexStore.class).to(HeapIndexStore.class).asEagerSingleton();
} else {
throw new ElasticSearchIllegalArgumentException("Memory location [" + location + "] is invalid, can be one of [direct,heap]");
}

View File

@ -0,0 +1,46 @@
/*
* 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.store.ram;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.store.IndexStore;
import org.elasticsearch.index.store.Store;
/**
* @author kimchy (shay.banon)
*/
public class RamIndexStore extends AbstractIndexComponent implements IndexStore {
@Inject public RamIndexStore(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings);
}
@Override public boolean persistent() {
return false;
}
@Override public Class<? extends Store> shardStoreClass() {
return RamStore.class;
}
}

View File

@ -20,14 +20,14 @@
package org.elasticsearch.index.store.ram;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.IndexStore;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class RamStoreModule extends AbstractModule {
public class RamIndexStoreModule extends AbstractModule {
@Override protected void configure() {
bind(Store.class).to(RamStore.class).asEagerSingleton();
bind(IndexStore.class).to(RamIndexStore.class).asEagerSingleton();
}
}

View File

@ -48,6 +48,7 @@ import org.elasticsearch.index.routing.OperationRoutingModule;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.index.similarity.SimilarityModule;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
import org.elasticsearch.plugins.IndicesPluginsModule;
@ -167,7 +168,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
indicesLifecycle.beforeIndexCreated(index);
logger.debug("Creating Index [{}], shards [{}]/[{}]", new Object[]{sIndexName, settings.get(SETTING_NUMBER_OF_SHARDS), settings.get(SETTING_NUMBER_OF_REPLICAS)});
logger.debug("Creating Index [{}], shards [{}]/[{}]", sIndexName, settings.get(SETTING_NUMBER_OF_SHARDS), settings.get(SETTING_NUMBER_OF_REPLICAS));
Settings indexSettings = settingsBuilder()
.put("settingsType", "index")
@ -182,6 +183,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
modules.add(new LocalNodeIdModule(localNodeId));
modules.add(new IndexSettingsModule(indexSettings));
modules.add(new IndicesPluginsModule(indexSettings, pluginsService));
modules.add(new IndexStoreModule(indexSettings));
modules.add(new IndexEngineModule(indexSettings));
modules.add(new AnalysisModule(indexSettings, indicesAnalysisService));
modules.add(new SimilarityModule(indexSettings));