Skip to content

Commit

Permalink
Single node rolling restart into a new node can cause metadata loss, c…
Browse files Browse the repository at this point in the history
…loses #1249.
  • Loading branch information
kimchy committed Aug 16, 2011
1 parent da56a4d commit be7d3b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class LocalGateway extends AbstractLifecycleComponent<Gateway> implements

private volatile boolean initialized = false;

private volatile boolean metaDataPersistedAtLeastOnce = false;

@Inject public LocalGateway(Settings settings, ClusterService clusterService, NodeEnvironment nodeEnv,
TransportNodesListGatewayMetaState listGatewayMetaState, TransportNodesListGatewayStartedShards listGatewayStartedShards) {
super(settings);
Expand Down Expand Up @@ -193,7 +195,7 @@ public LocalGatewayStartedShards currentStartedShards() {
}

// we only write the local metadata if this is a possible master node
if (event.state().nodes().localNode().masterNode() && event.metaDataChanged()) {
if (event.state().nodes().localNode().masterNode() && (event.metaDataChanged() || !metaDataPersistedAtLeastOnce)) {
executor.execute(new LoggingRunnable(logger, new PersistMetaData(event)));
}

Expand Down Expand Up @@ -443,6 +445,7 @@ public PersistMetaData(ClusterChangedEvent event) {
} catch (IOException e) {
logger.warn("failed to write updated state", e);
}
metaDataPersistedAtLeastOnce = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.action.admin.indices.status.ShardStatus;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.test.integration.AbstractNodesTests;
Expand Down Expand Up @@ -365,4 +366,31 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests {
}
}
}

@Test public void testRecoveryDifferentNodeOrderStartup() throws Exception {
// we need different data paths so we make sure we start the second node fresh
buildNode("node1", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data1").build());
buildNode("node2", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data2").build());
cleanAndCloseNodes();

startNode("node1", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data1").build());

client("node1").prepareIndex("test", "type1", "1").setSource("field", "value").execute().actionGet();

startNode("node2", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data2").build());

ClusterHealthResponse health = client("node2").admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
assertThat(health.timedOut(), equalTo(false));

closeNode("node1");
closeNode("node2");

startNode("node2", settingsBuilder().put("gateway.type", "local").put("path.data", "data/data2").build());

health = client("node2").admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
assertThat(health.timedOut(), equalTo(false));

assertThat(client("node2").admin().indices().prepareExists("test").execute().actionGet().exists(), equalTo(true));
assertThat(client("node2").prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(1l));
}
}

0 comments on commit be7d3b6

Please sign in to comment.