Throw AssertionError when no master (#38432)
Today we throw a fatal `RuntimeException` if an exception occurs in `getMasterName()`, and this includes the case where there is currently no master. However, sometimes we call this method inside an `assertBusy()` in order to allow for a cluster that is in the process of stabilising and electing a master. The trouble is that `assertBusy()` only retries on an `AssertionError` and not on a general `RuntimeException`, so the lack of a master is immediately fatal. This commit fixes the issue by asserting there is a master, triggering a retry if there is not. Fixes #38331
This commit is contained in:
parent
12657fda44
commit
b7ab521eb1
|
@ -84,7 +84,6 @@ public class SpecificMasterNodesIT extends ESIntegTestCase {
|
|||
.execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligibleNodeName));
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/38331")
|
||||
public void testElectOnlyBetweenMasterNodes() throws Exception {
|
||||
internalCluster().setBootstrapMasterNodeIndex(0);
|
||||
logger.info("--> start data node / non master node");
|
||||
|
|
|
@ -167,6 +167,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -1909,8 +1910,9 @@ public final class InternalTestCluster extends TestCluster {
|
|||
public String getMasterName(@Nullable String viaNode) {
|
||||
try {
|
||||
Client client = viaNode != null ? client(viaNode) : client();
|
||||
ClusterState state = client.admin().cluster().prepareState().execute().actionGet().getState();
|
||||
return state.nodes().getMasterNode().getName();
|
||||
final DiscoveryNode masterNode = client.admin().cluster().prepareState().get().getState().nodes().getMasterNode();
|
||||
assertNotNull(masterNode);
|
||||
return masterNode.getName();
|
||||
} catch (Exception e) {
|
||||
logger.warn("Can't fetch cluster state", e);
|
||||
throw new RuntimeException("Can't get master node " + e.getMessage(), e);
|
||||
|
|
Loading…
Reference in New Issue