refactor node data location of index and shard into common code

This commit is contained in:
kimchy 2010-11-03 15:07:23 +02:00
parent 6804c02e97
commit 6e0180db6a
4 changed files with 17 additions and 4 deletions

View File

@ -25,6 +25,8 @@ import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -98,6 +100,14 @@ public class NodeEnvironment extends AbstractComponent {
return nodeFile; return nodeFile;
} }
public File indexLocation(Index index) {
return new File(new File(nodeDataLocation(), "indices"), index.name());
}
public File shardLocation(ShardId shardId) {
return new File(indexLocation(shardId.index()), Integer.toString(shardId.id()));
}
public void close() { public void close() {
if (lock != null) { if (lock != null) {
try { try {

View File

@ -38,12 +38,15 @@ import java.io.IOException;
*/ */
public abstract class FsIndexStore extends AbstractIndexStore { public abstract class FsIndexStore extends AbstractIndexStore {
private final NodeEnvironment nodeEnv;
private final File location; private final File location;
public FsIndexStore(Index index, @IndexSettings Settings indexSettings, IndexService indexService, NodeEnvironment nodeEnv) { public FsIndexStore(Index index, @IndexSettings Settings indexSettings, IndexService indexService, NodeEnvironment nodeEnv) {
super(index, indexSettings, indexService); super(index, indexSettings, indexService);
this.nodeEnv = nodeEnv;
if (nodeEnv.hasNodeFile()) { if (nodeEnv.hasNodeFile()) {
this.location = new File(new File(nodeEnv.nodeDataLocation(), "indices"), index.name()); this.location = nodeEnv.indexLocation(index);
} else { } else {
this.location = null; this.location = null;
} }
@ -86,7 +89,7 @@ public abstract class FsIndexStore extends AbstractIndexStore {
} }
public File shardLocation(ShardId shardId) { public File shardLocation(ShardId shardId) {
return new File(location, Integer.toString(shardId.id())); return nodeEnv.shardLocation(shardId);
} }
public File shardIndexLocation(ShardId shardId) { public File shardIndexLocation(ShardId shardId) {

View File

@ -60,7 +60,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog
@Inject public FsTranslog(ShardId shardId, @IndexSettings Settings indexSettings, NodeEnvironment nodeEnv) { @Inject public FsTranslog(ShardId shardId, @IndexSettings Settings indexSettings, NodeEnvironment nodeEnv) {
super(shardId, indexSettings); super(shardId, indexSettings);
this.location = new File(new File(new File(new File(nodeEnv.nodeDataLocation(), "indices"), shardId.index().name()), Integer.toString(shardId.id())), "translog"); this.location = new File(nodeEnv.shardLocation(shardId), "translog");
this.location.mkdirs(); this.location.mkdirs();
this.useStream = componentSettings.getAsBoolean("use_stream", false); this.useStream = componentSettings.getAsBoolean("use_stream", false);
} }

View File

@ -153,7 +153,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio
if (!storeType.contains("fs")) { if (!storeType.contains("fs")) {
return new StoreFilesMetaData(false, shardId, ImmutableMap.<String, StoreFileMetaData>of()); return new StoreFilesMetaData(false, shardId, ImmutableMap.<String, StoreFileMetaData>of());
} }
File indexFile = new File(new File(new File(new File(nodeEnv.nodeDataLocation(), "indices"), shardId.index().name()), Integer.toString(shardId.id())), "index"); File indexFile = new File(nodeEnv.shardLocation(shardId), "index");
if (!indexFile.exists()) { if (!indexFile.exists()) {
return new StoreFilesMetaData(false, shardId, ImmutableMap.<String, StoreFileMetaData>of()); return new StoreFilesMetaData(false, shardId, ImmutableMap.<String, StoreFileMetaData>of());
} }