From 770ccf421b468f518fffbd7671632569f49d59cb Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 4 Nov 2010 12:17:17 +0200 Subject: [PATCH] don't write the local gateway state if there is no master, since we don't want to override the fact that they do exists on that node under the respective version --- .../java/org/elasticsearch/cluster/block/ClusterBlocks.java | 4 ++++ .../main/java/org/elasticsearch/discovery/Discovery.java | 4 ++++ .../java/org/elasticsearch/discovery/zen/ZenDiscovery.java | 4 ---- .../java/org/elasticsearch/gateway/local/LocalGateway.java | 6 +++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java index 3278f2dd056..9b946a405b6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java @@ -91,6 +91,10 @@ public class ClusterBlocks { return levelHolders[level.id()].indices(); } + public boolean hasGlobalBlock(ClusterBlock block) { + return global.contains(block); + } + public boolean hasIndexBlock(String index, ClusterBlock block) { return indicesBlocks.containsKey(index) && indicesBlocks.get(index).contains(block); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java index 3889bd919d9..d3e195ee285 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/Discovery.java @@ -20,6 +20,8 @@ package org.elasticsearch.discovery; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlock; +import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.LifecycleComponent; @@ -32,6 +34,8 @@ import org.elasticsearch.common.component.LifecycleComponent; */ public interface Discovery extends LifecycleComponent { + final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", ClusterBlockLevel.ALL); + DiscoveryNode localNode(); void addListener(InitialStateDiscoveryListener listener); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 95e4edaa97e..295db4655fa 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -22,8 +22,6 @@ package org.elasticsearch.discovery.zen; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.*; -import org.elasticsearch.cluster.block.ClusterBlock; -import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -63,8 +61,6 @@ import static org.elasticsearch.common.unit.TimeValue.*; */ public class ZenDiscovery extends AbstractLifecycleComponent implements Discovery, DiscoveryNodesProvider { - public final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", ClusterBlockLevel.ALL); - private final ThreadPool threadPool; private final TransportService transportService; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGateway.java index 2000c4faca0..7337bc40e67 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/gateway/local/LocalGateway.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.*; +import org.elasticsearch.discovery.Discovery; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.gateway.GatewayException; @@ -222,7 +223,10 @@ public class LocalGateway extends AbstractLifecycleComponent implements return; } - if (event.state().nodes().localNode().masterNode() && event.metaDataChanged()) { + // we only write the local metadata if this is a possible master node, the metadata has changed, and + // we don't have a NO_MASTER block (in which case, the routing is cleaned, and we don't want to override what + // we have now, since it might be needed when later on performing full state recovery) + if (event.state().nodes().localNode().masterNode() && event.metaDataChanged() && !event.state().blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK)) { executor.execute(new Runnable() { @Override public void run() { LocalGatewayMetaState.Builder builder = LocalGatewayMetaState.builder();