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

This commit is contained in:
kimchy 2010-11-04 12:17:17 +02:00
parent e2d6f82cd3
commit 770ccf421b
4 changed files with 13 additions and 5 deletions

View File

@ -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);
}

View File

@ -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<Discovery> {
final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", ClusterBlockLevel.ALL);
DiscoveryNode localNode();
void addListener(InitialStateDiscoveryListener listener);

View File

@ -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<Discovery> implements Discovery, DiscoveryNodesProvider {
public final ClusterBlock NO_MASTER_BLOCK = new ClusterBlock(2, "no master", ClusterBlockLevel.ALL);
private final ThreadPool threadPool;
private final TransportService transportService;

View File

@ -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<Gateway> 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();