Skip to content

Commit a122221

Browse files
author
Andrey Ershov
committed
Special message for must join elected master in ClusterFormationHelper
1 parent 699cfc0 commit a122221

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

server/src/main/java/org/elasticsearch/cluster/coordination/ClusterFormationFailureHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ String getDescription() {
167167

168168
assert clusterState.getLastCommittedConfiguration().isEmpty() == false;
169169

170+
if (clusterState.getLastCommittedConfiguration().equals(VotingConfiguration.MUST_JOIN_ELECTED_MASTER)) {
171+
return String.format(Locale.ROOT,
172+
"master not discovered yet and this node was detached from its previous cluster, have discovered %s; %s",
173+
foundPeers, discoveryWillContinueDescription);
174+
}
175+
170176
final String quorumDescription;
171177
if (clusterState.getLastAcceptedConfiguration().equals(clusterState.getLastCommittedConfiguration())) {
172178
quorumDescription = describeQuorum(clusterState.getLastAcceptedConfiguration());

server/src/test/java/org/elasticsearch/cluster/coordination/ClusterFormationFailureHelperTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,42 @@ private static ClusterState state(DiscoveryNode localNode, String[] acceptedConf
201201
.lastCommittedConfiguration(config(committedConfig)).build())).build();
202202
}
203203

204+
205+
public void testDescriptionAfterDetachCluster() {
206+
final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
207+
208+
final ClusterState clusterState = state(localNode,
209+
VotingConfiguration.MUST_JOIN_ELECTED_MASTER.getNodeIds().toArray(new String[0]));
210+
211+
assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), emptyList(), 0L).getDescription(),
212+
is("master not discovered yet and this node was detached from its previous cluster, " +
213+
"have discovered []; " +
214+
"discovery will continue using [] from hosts providers and [" + localNode +
215+
"] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
216+
217+
final TransportAddress otherAddress = buildNewFakeTransportAddress();
218+
assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, singletonList(otherAddress), emptyList(), 0L).getDescription(),
219+
is("master not discovered yet and this node was detached from its previous cluster, " +
220+
"have discovered []; " +
221+
"discovery will continue using [" + otherAddress + "] from hosts providers and [" + localNode +
222+
"] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
223+
224+
final DiscoveryNode otherNode = new DiscoveryNode("otherNode", buildNewFakeTransportAddress(), Version.CURRENT);
225+
assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), singletonList(otherNode), 0L).getDescription(),
226+
is("master not discovered yet and this node was detached from its previous cluster, " +
227+
"have discovered [" + otherNode + "]; " +
228+
"discovery will continue using [] from hosts providers and [" + localNode +
229+
"] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
230+
231+
final DiscoveryNode yetAnotherNode = new DiscoveryNode("yetAnotherNode", buildNewFakeTransportAddress(), Version.CURRENT);
232+
assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), singletonList(yetAnotherNode), 0L).getDescription(),
233+
is("master not discovered yet and this node was detached from its previous cluster, " +
234+
"have discovered [" + yetAnotherNode + "]; " +
235+
"discovery will continue using [] from hosts providers and [" + localNode +
236+
"] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
237+
238+
}
239+
204240
public void testDescriptionAfterBootstrapping() {
205241
final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
206242

0 commit comments

Comments
 (0)