Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce cluster UUIDs #37775

Merged
merged 20 commits into from
Jan 29, 2019
Merged

Enforce cluster UUIDs #37775

merged 20 commits into from
Jan 29, 2019

Conversation

ywelsch
Copy link
Contributor

@ywelsch ywelsch commented Jan 23, 2019

This PR adds join validation around cluster UUIDs, preventing a node to join a cluster if it was previously part of another cluster.

The PR introduces a new flag to the cluster state, clusterUUIDCommitted, which denotes whether the node has locked into a cluster with the given uuid. When a cluster is committed, this flag will turn to true, and subsequent cluster state updates will keep the information about committal.

Note that coordinating-only nodes are still free to switch clusters at will (after restart), as they don't carry any persistent state.

@ywelsch ywelsch added >enhancement WIP :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. labels Jan 23, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@ywelsch ywelsch mentioned this pull request Jan 23, 2019
61 tasks
@ywelsch ywelsch changed the title [WIP] Enforce cluster UUIDs Enforce cluster UUIDs Jan 24, 2019
@ywelsch ywelsch removed the WIP label Jan 24, 2019
@ywelsch
Copy link
Contributor Author

ywelsch commented Jan 24, 2019

@DaveCTurner @andrershov this is ready for a first review

Copy link
Contributor

@andrershov andrershov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added minor comments.
It also would be nice to add integration test, similar to testIndexImportedFromDataOnlyNodesIfMasterLostDataFolder or RecoveryFromGatewayIT.testTwoNodeFirstNodeCleared that will clear data folder of master eligible node and after that data node won't be able to join the cluster because join validation will fail due to clusterUUID mismatch.

final ClusterState localState = currentStateSupplier.get();
if (localState.metaData().clusterUUIDCommitted() &&
localState.metaData().clusterUUID().equals(request.getState().metaData().clusterUUID()) == false) {
throw new CoordinationStateRejectedException("join validation on cluster state" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason why we log warning message in Coordinator, but do not log it here?

shiftedNode.getLocalNode(), n -> shiftedNode.persistedState);
cluster1.clusterNodes.add(newNode);

MockLogAppender mockAppender = new MockLogAppender();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pity that we don't have a better way of understanding that join validation has failed, other than analyzing log output

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to that. Why can't we e.g. call cluster1.runFor(DEFAULT_STABILISATION_TIME) and then assert that the node didn't manage to join the cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've extended it to DEFAULT_STABILISATION_TIME, but I also want to make sure it fails for the right reason, hence keeping the logging check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all ears if you have better suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about asserting that if we change nothing except the cluster UUID on disk then the node does join the cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there is no guarantee that it will if it has same term but higher version than master? I think these kinds of tests will be more useful after having the detach-cluster tool.

.coordinationMetaData(CoordinationMetaData.builder(metaData.coordinationMetaData())
.term(0L).build())
.build(),
term -> 0L);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that resetting term and currentTerm to 0 was required? shall we do the same in elasticsearch-node tool? What about version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this was required. I'll leave the definitive way to the tool (added TODO in c3e0aa2)

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I left a few small comments.

@@ -268,7 +268,7 @@ public void testMixCurrentAndRecoveredState() {
final ClusterState updatedState = mixCurrentStateAndRecoveredState(currentState, recoveredState);

assertThat(updatedState.metaData().clusterUUID(), not(equalTo("_na_")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should really use UNKNOWN_CLUSTER_UUID here and elsewhere in the tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see 3dc2c62

metaDataBuilder = MetaData.builder(lastAcceptedState.metaData());
metaDataBuilder.coordinationMetaData(coordinationMetaData);
}
if (lastAcceptedState.metaData().clusterUUID().equals(MetaData.UNKNOWN_CLUSTER_UUID) == false &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we commit a state without a cluster UUID? Feels like this should be an assertion to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the master node is a Zen1 node that has not recovered its state yet, that can unfortunately be the case (testMixedClusterFormation found this). I've added an assertion to that effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write the assertion in a way that means we will have to remove it when Zen1 is no more? E.g. mention ZEN1_BWC_TERM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 2697b44

final ClusterNode shiftedNode = randomFrom(cluster2.clusterNodes).restartedNode();
final ClusterNode newNode = cluster1.new ClusterNode(nextNodeIndex.getAndIncrement(),
shiftedNode.getLocalNode(), n -> shiftedNode.persistedState);
cluster1.clusterNodes.add(newNode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

shiftedNode.getLocalNode(), n -> shiftedNode.persistedState);
cluster1.clusterNodes.add(newNode);

MockLogAppender mockAppender = new MockLogAppender();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to that. Why can't we e.g. call cluster1.runFor(DEFAULT_STABILISATION_TIME) and then assert that the node didn't manage to join the cluster?

@ywelsch
Copy link
Contributor Author

ywelsch commented Jan 29, 2019

@elasticmachine run elasticsearch-ci/1
@elasticmachine run elasticsearch-ci/default-distro

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but there are still some open questions from @andrershov.

Copy link
Contributor

@andrershov andrershov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM2, the only unanswered question is about logging, but I guess it's done this way to simplify testing.

@ywelsch
Copy link
Contributor Author

ywelsch commented Jan 29, 2019

@elasticmachine what have you done?

@ywelsch ywelsch merged commit 3c9f703 into elastic:master Jan 29, 2019
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Apr 10, 2019
Today we fail to join a Zen2 cluster if the cluster UUID does not match our
own, but we do not perform the same validation when joining a Zen1 cluster.
This means that a Zen2 node will pass join validation and be added to a Zen1
cluster but will reject all cluster states from the master.

Relates elastic#37775
DaveCTurner added a commit that referenced this pull request Apr 16, 2019
Today we fail to join a Zen2 cluster if the cluster UUID does not match our
own, but we do not perform the same validation when joining a Zen1 cluster.
This means that a Zen2 node will pass join validation and be added to a Zen1
cluster but will reject all cluster states from the master.

Relates #37775
DaveCTurner added a commit that referenced this pull request Apr 16, 2019
Today we fail to join a Zen2 cluster if the cluster UUID does not match our
own, but we do not perform the same validation when joining a Zen1 cluster.
This means that a Zen2 node will pass join validation and be added to a Zen1
cluster but will reject all cluster states from the master.

Relates #37775
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Apr 16, 2019
This is a forward-port of parts of elastic#41063 to `master`, adding a test to show
that join validation does indeed verify that the cluster UUIDs match.

Relates elastic#37775
DaveCTurner added a commit that referenced this pull request Apr 16, 2019
This is a forward-port of parts of #41063 to `master`, adding a test to show
that join validation does indeed verify that the cluster UUIDs match.

Relates #37775
gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this pull request May 27, 2019
This is a forward-port of parts of elastic#41063 to `master`, adding a test to show
that join validation does indeed verify that the cluster UUIDs match.

Relates elastic#37775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. >enhancement v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants