From a0ead0229970a0381c26522bbfd494f1e9e5e007 Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 10 Jul 2010 14:29:39 +0300 Subject: [PATCH] Don't create / use the work directory if not needed (for example, on client / non data) nodes, closes #249. --- .../nodes/TransportNodesOperationAction.java | 7 +++- .../org/elasticsearch/env/Environment.java | 3 -- .../elasticsearch/env/NodeEnvironment.java | 14 ++++++++ .../index/store/fs/FsIndexStore.java | 35 +++++++++++-------- .../TransportNodesListShardStoreMetaData.java | 15 ++++++++ .../monitor/dump/DumpMonitorService.java | 1 - 6 files changed, 56 insertions(+), 19 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java index 1e00ebec34d..40ea81d7f23 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesOperationAction.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; @@ -83,6 +84,10 @@ public abstract class TransportNodesOperationAction(nodesIds.length); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java b/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java index 6d4ed558b49..4c9de24c4cf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/env/Environment.java @@ -62,7 +62,6 @@ public class Environment { } else { homeFile = new File(System.getProperty("user.dir")); } - homeFile.mkdirs(); if (settings.get("path.conf") != null) { configFile = new File(cleanPath(settings.get("path.conf"))); @@ -81,9 +80,7 @@ public class Environment { } else { workFile = new File(homeFile, "work"); } - workFile.mkdirs(); workWithClusterFile = new File(workFile, ClusterName.clusterNameFromSettings(settings).value()); - workWithClusterFile.mkdirs(); if (settings.get("path.logs") != null) { logsFile = new File(cleanPath(settings.get("path.logs"))); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/modules/elasticsearch/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 236cb794f8e..427433cfdc8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -21,6 +21,7 @@ package org.elasticsearch.env; import org.apache.lucene.store.Lock; import org.apache.lucene.store.NativeFSLockFactory; +import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -48,6 +49,12 @@ public class NodeEnvironment extends AbstractComponent { @Inject public NodeEnvironment(Settings settings, Environment environment) throws IOException { super(settings); + if (!settings.getAsBoolean("node.data", true) || settings.getAsBoolean("node.client", false)) { + nodeFile = null; + lock = null; + return; + } + Lock lock = null; File dir = null; for (int i = 0; i < 100; i++) { @@ -77,7 +84,14 @@ public class NodeEnvironment extends AbstractComponent { } } + public boolean hasNodeFile() { + return nodeFile != null && lock != null; + } + public File nodeFile() { + if (nodeFile == null || lock == null) { + throw new ElasticSearchIllegalStateException("node is not configured to store local location"); + } return nodeFile; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/FsIndexStore.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/FsIndexStore.java index 5efb1bf91f9..e0842a3d3c7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/FsIndexStore.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/store/fs/FsIndexStore.java @@ -54,14 +54,10 @@ public abstract class FsIndexStore extends AbstractIndexStore { public FsIndexStore(Index index, @IndexSettings Settings indexSettings, IndexService indexService, NodeEnvironment nodeEnv) { super(index, indexSettings, indexService); - this.location = new File(new File(nodeEnv.nodeFile(), "indices"), index.name()); - - if (!location.exists()) { - for (int i = 0; i < 5; i++) { - if (location.mkdirs()) { - break; - } - } + if (nodeEnv.hasNodeFile()) { + this.location = new File(new File(nodeEnv.nodeFile(), "indices"), index.name()); + } else { + this.location = null; } } @@ -70,22 +66,31 @@ public abstract class FsIndexStore extends AbstractIndexStore { } @Override public ByteSizeValue backingStoreTotalSpace() { + if (location == null) { + return new ByteSizeValue(0); + } long totalSpace = location.getTotalSpace(); if (totalSpace == 0) { - totalSpace = -1; + totalSpace = 0; } return new ByteSizeValue(totalSpace); } @Override public ByteSizeValue backingStoreFreeSpace() { + if (location == null) { + return new ByteSizeValue(0); + } long usableSpace = location.getUsableSpace(); if (usableSpace == 0) { - usableSpace = -1; + usableSpace = 0; } return new ByteSizeValue(usableSpace); } @Override public void deleteUnallocated(ShardId shardId) throws IOException { + if (location == null) { + return; + } if (indexService.hasShard(shardId.id())) { throw new ElasticSearchIllegalStateException(shardId + " allocated, can't be deleted"); } @@ -93,6 +98,9 @@ public abstract class FsIndexStore extends AbstractIndexStore { } @Override public StoreFilesMetaData[] listUnallocatedStores() throws IOException { + if (location == null) { + return new StoreFilesMetaData[0]; + } File[] shardLocations = location.listFiles(); if (shardLocations == null || shardLocations.length == 0) { return new StoreFilesMetaData[0]; @@ -108,6 +116,9 @@ public abstract class FsIndexStore extends AbstractIndexStore { } @Override protected StoreFilesMetaData listUnallocatedStoreMetaData(ShardId shardId) throws IOException { + if (location == null) { + return new StoreFilesMetaData(false, shardId, ImmutableMap.of()); + } File shardIndexLocation = shardIndexLocation(shardId); if (!shardIndexLocation.exists()) { return new StoreFilesMetaData(false, shardId, ImmutableMap.of()); @@ -139,10 +150,6 @@ public abstract class FsIndexStore extends AbstractIndexStore { return cachedUnallocatedMd5s.get(shardId); } - public File location() { - return location; - } - public File shardLocation(ShardId shardId) { return new File(location, Integer.toString(shardId.id())); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index e7b2dadfb40..f4f232be641 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -25,7 +25,9 @@ import org.elasticsearch.action.support.nodes.*; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.collect.Lists; +import org.elasticsearch.common.collect.Sets; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -39,6 +41,7 @@ import org.elasticsearch.transport.TransportService; import java.io.IOException; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicReferenceArray; /** @@ -82,6 +85,18 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesOperatio return new NodeStoreFilesMetaData(); } + // only list stores on data node + + @Override protected String[] filterNodeIds(DiscoveryNodes nodes, String[] nodesIds) { + Set onlyDataNodeIds = Sets.newHashSet(); + for (String nodeId : nodesIds) { + if (nodes.nodeExists(nodeId) && nodes.get(nodeId).dataNode()) { + onlyDataNodeIds.add(nodeId); + } + } + return onlyDataNodeIds.toArray(new String[onlyDataNodeIds.size()]); + } + @Override protected NodesStoreFilesMetaData newResponse(Request request, AtomicReferenceArray responses) { final List nodeStoreFilesMetaDatas = Lists.newArrayList(); for (int i = 0; i < responses.length(); i++) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java index b865336a078..dcc7f05d92e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/dump/DumpMonitorService.java @@ -72,7 +72,6 @@ public class DumpMonitorService extends AbstractComponent { } else { dumpLocationFile = new File(workFile, "dump"); } - boolean success = dumpLocationFile.mkdirs(); Map contributorMap = newHashMap(); if (contributors != null) {