From e0508809cb08e7e03cc0a53bc7f77f9b08daeaee Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Wed, 1 Feb 2012 00:29:49 +0200 Subject: [PATCH] new local gateway should only load state if its data (for shards state) or master (for metadata) and not try and load if its not (so we don't load if its a client node) --- .../cluster/node/DiscoveryNode.java | 23 +++++++++++++++++-- .../state/meta/LocalGatewayMetaState.java | 19 ++++++++------- .../state/shards/LocalGatewayShardsState.java | 19 ++++++++------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 6338fc03a4f..df0a39391a5 100644 --- a/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -37,8 +37,6 @@ import static org.elasticsearch.common.transport.TransportAddressSerializers.add /** * A discovery node represents a node that is part of the cluster. - * - * */ public class DiscoveryNode implements Streamable, Serializable { @@ -46,6 +44,27 @@ public class DiscoveryNode implements Streamable, Serializable { return !(settings.getAsBoolean("node.client", false) || (!settings.getAsBoolean("node.data", true) && !settings.getAsBoolean("node.master", true))); } + public static boolean clientNode(Settings settings) { + String client = settings.get("node.client"); + return client != null && client.equals("true"); + } + + public static boolean masterNode(Settings settings) { + String master = settings.get("node.master"); + if (master == null) { + return !clientNode(settings); + } + return master.equals("true"); + } + + public static boolean dataNode(Settings settings) { + String data = settings.get("data"); + if (data == null) { + return !clientNode(settings); + } + return data.equals("true"); + } + public static final ImmutableList EMPTY_LIST = ImmutableList.of(); private String nodeName = "".intern(); diff --git a/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalGatewayMetaState.java b/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalGatewayMetaState.java index daf32fdf1d5..2c58b8fc14d 100644 --- a/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalGatewayMetaState.java +++ b/src/main/java/org/elasticsearch/gateway/local/state/meta/LocalGatewayMetaState.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; @@ -73,14 +74,16 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS formatParams = ToXContent.EMPTY_PARAMS; } - try { - pre019Upgrade(); - long start = System.currentTimeMillis(); - loadState(); - logger.debug("took {} to load state", TimeValue.timeValueMillis(System.currentTimeMillis() - start)); - } catch (Exception e) { - logger.error("failed to read local state, exiting...", e); - throw e; + if (DiscoveryNode.masterNode(settings)) { + try { + pre019Upgrade(); + long start = System.currentTimeMillis(); + loadState(); + logger.debug("took {} to load state", TimeValue.timeValueMillis(System.currentTimeMillis() - start)); + } catch (Exception e) { + logger.error("failed to read local state, exiting...", e); + throw e; + } } } diff --git a/src/main/java/org/elasticsearch/gateway/local/state/shards/LocalGatewayShardsState.java b/src/main/java/org/elasticsearch/gateway/local/state/shards/LocalGatewayShardsState.java index 81ffef6a1f6..22c7c6fb700 100644 --- a/src/main/java/org/elasticsearch/gateway/local/state/shards/LocalGatewayShardsState.java +++ b/src/main/java/org/elasticsearch/gateway/local/state/shards/LocalGatewayShardsState.java @@ -23,6 +23,7 @@ import com.google.common.collect.Maps; import com.google.common.io.Closeables; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterStateListener; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.*; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; @@ -62,14 +63,16 @@ public class LocalGatewayShardsState extends AbstractComponent implements Cluste this.nodeEnv = nodeEnv; listGatewayStartedShards.initGateway(this); - try { - pre019Upgrade(); - long start = System.currentTimeMillis(); - loadStartedShards(); - logger.debug("took {} to load started shards state", TimeValue.timeValueMillis(System.currentTimeMillis() - start)); - } catch (Exception e) { - logger.error("failed to read local state (started shards), exiting...", e); - throw e; + if (DiscoveryNode.dataNode(settings)) { + try { + pre019Upgrade(); + long start = System.currentTimeMillis(); + loadStartedShards(); + logger.debug("took {} to load started shards state", TimeValue.timeValueMillis(System.currentTimeMillis() - start)); + } catch (Exception e) { + logger.error("failed to read local state (started shards), exiting...", e); + throw e; + } } }