Skip to content

Commit

Permalink
Do not retry if bootstrapping throws an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Jan 17, 2019
1 parent 7d70a29 commit 2ff94a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,7 @@ private void doBootstrap(VotingConfiguration votingConfiguration) {
try {
votingConfigurationConsumer.accept(votingConfiguration);
} catch (Exception e) {
logger.warn(new ParameterizedMessage("exception when bootstrapping with {}, rescheduling", votingConfiguration), e);
transportService.getThreadPool().scheduleUnlessShuttingDown(TimeValue.timeValueSeconds(10), Names.GENERIC,
new Runnable() {
@Override
public void run() {
doBootstrap(votingConfiguration);
}

@Override
public String toString() {
return "retry of failed bootstrapping with " + votingConfiguration;
}
}
);
logger.warn(new ParameterizedMessage("failed to bootstrap with {}", votingConfiguration), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.cluster.coordination;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNode.Role;
Expand All @@ -31,7 +30,6 @@

import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -217,23 +215,18 @@ public void testDoesNotBootstrapsIfZen1NodesDiscovered() {
deterministicTaskQueue.runAllTasks();
}

public void testRetriesBootstrappingOnException() {

final AtomicLong bootstrappingAttempts = new AtomicLong();
public void testDoesNotRetryBootstrappingOnException() {
final AtomicBoolean bootstrappingAttempted = new AtomicBoolean();
ClusterBootstrapService clusterBootstrapService = new ClusterBootstrapService(Settings.builder().putList(
INITIAL_MASTER_NODES_SETTING.getKey(), localNode.getName(), otherNode1.getName(), otherNode2.getName()).build(),
transportService, () -> Stream.of(otherNode1, otherNode2).collect(Collectors.toList()), vc -> {
bootstrappingAttempts.incrementAndGet();
if (bootstrappingAttempts.get() < 5L) {
throw new ElasticsearchException("test");
}
assertTrue(bootstrappingAttempted.compareAndSet(false, true));
});

transportService.start();
clusterBootstrapService.onFoundPeersUpdated();
deterministicTaskQueue.runAllTasks();
assertThat(bootstrappingAttempts.get(), greaterThanOrEqualTo(5L));
assertThat(deterministicTaskQueue.getCurrentTimeMillis(), greaterThanOrEqualTo(40000L));
assertTrue(bootstrappingAttempted.get());
}

public void testDoesNotBootstrapIfRequirementNotMet() {
Expand Down

0 comments on commit 2ff94a0

Please sign in to comment.