From 9283e2a7ad364b7702dc85ee844f7cbb89da9bb4 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 23 Jul 2010 01:39:37 +0300 Subject: [PATCH] local discovery should update the local metadata state once it started --- .../discovery/local/LocalDiscovery.java | 14 +++++++++++++- .../integration/recovery/SimpleRecoveryTests.java | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java index ee8afa6685d..784c9d13200 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java @@ -106,11 +106,23 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem } else { // we are not the master, tell the master to send it LocalDiscovery master = clusterGroup.members().peek(); + + // update as fast as we can the local node state with the new metadata (so we create indices for example) + final ClusterState masterState = master.clusterService.state(); + clusterService.submitStateUpdateTask("local-disco(detected_master)", new ClusterStateUpdateTask() { + @Override public ClusterState execute(ClusterState currentState) { + // make sure we have the local node id set, we might need it as a result of the new metadata + DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.newNodesBuilder().putAll(currentState.nodes()).put(localNode).localNodeId(localNode.id()); + return ClusterState.builder().state(currentState).metaData(masterState.metaData()).nodes(nodesBuilder).build(); + } + }); + + // tell the master to send the fact that we are here master.clusterService.submitStateUpdateTask("local-disco-receive(from node[" + localNode + "])", new ProcessedClusterStateUpdateTask() { @Override public ClusterState execute(ClusterState currentState) { if (currentState.nodes().nodeExists(localNode.id())) { // no change, the node already exists in the cluster - logger.warn("Received an address [{}] for an existing node [{}]", localNode.address(), localNode); + logger.warn("received an address [{}] for an existing node [{}]", localNode.address(), localNode); return currentState; } return newClusterStateBuilder().state(currentState).nodes(currentState.nodes().newNode(localNode)).build(); diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/recovery/SimpleRecoveryTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/recovery/SimpleRecoveryTests.java index 948f9f0a6c0..25321e59ba0 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/recovery/SimpleRecoveryTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/recovery/SimpleRecoveryTests.java @@ -86,8 +86,9 @@ public class SimpleRecoveryTests extends AbstractNodesTests { // now start another one so we move some primaries startNode("server3"); + Thread.sleep(200); logger.info("Running Cluster Health"); - clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForNodes("3")).actionGet(); + clusterHealth = client("server1").admin().cluster().health(clusterHealth().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet(); logger.info("Done Cluster Health, status " + clusterHealth.status()); assertThat(clusterHealth.timedOut(), equalTo(false)); assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));