Skip to content

Commit 2ff94a0

Browse files
committed
Do not retry if bootstrapping throws an exception
1 parent 7d70a29 commit 2ff94a0

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,7 @@ private void doBootstrap(VotingConfiguration votingConfiguration) {
150150
try {
151151
votingConfigurationConsumer.accept(votingConfiguration);
152152
} catch (Exception e) {
153-
logger.warn(new ParameterizedMessage("exception when bootstrapping with {}, rescheduling", votingConfiguration), e);
154-
transportService.getThreadPool().scheduleUnlessShuttingDown(TimeValue.timeValueSeconds(10), Names.GENERIC,
155-
new Runnable() {
156-
@Override
157-
public void run() {
158-
doBootstrap(votingConfiguration);
159-
}
160-
161-
@Override
162-
public String toString() {
163-
return "retry of failed bootstrapping with " + votingConfiguration;
164-
}
165-
}
166-
);
153+
logger.warn(new ParameterizedMessage("failed to bootstrap with {}", votingConfiguration), e);
167154
}
168155
}
169156

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.cluster.coordination;
2020

21-
import org.elasticsearch.ElasticsearchException;
2221
import org.elasticsearch.Version;
2322
import org.elasticsearch.cluster.node.DiscoveryNode;
2423
import org.elasticsearch.cluster.node.DiscoveryNode.Role;
@@ -31,7 +30,6 @@
3130

3231
import java.util.Collections;
3332
import java.util.concurrent.atomic.AtomicBoolean;
34-
import java.util.concurrent.atomic.AtomicLong;
3533
import java.util.concurrent.atomic.AtomicReference;
3634
import java.util.function.Supplier;
3735
import java.util.stream.Collectors;
@@ -217,23 +215,18 @@ public void testDoesNotBootstrapsIfZen1NodesDiscovered() {
217215
deterministicTaskQueue.runAllTasks();
218216
}
219217

220-
public void testRetriesBootstrappingOnException() {
221-
222-
final AtomicLong bootstrappingAttempts = new AtomicLong();
218+
public void testDoesNotRetryBootstrappingOnException() {
219+
final AtomicBoolean bootstrappingAttempted = new AtomicBoolean();
223220
ClusterBootstrapService clusterBootstrapService = new ClusterBootstrapService(Settings.builder().putList(
224221
INITIAL_MASTER_NODES_SETTING.getKey(), localNode.getName(), otherNode1.getName(), otherNode2.getName()).build(),
225222
transportService, () -> Stream.of(otherNode1, otherNode2).collect(Collectors.toList()), vc -> {
226-
bootstrappingAttempts.incrementAndGet();
227-
if (bootstrappingAttempts.get() < 5L) {
228-
throw new ElasticsearchException("test");
229-
}
223+
assertTrue(bootstrappingAttempted.compareAndSet(false, true));
230224
});
231225

232226
transportService.start();
233227
clusterBootstrapService.onFoundPeersUpdated();
234228
deterministicTaskQueue.runAllTasks();
235-
assertThat(bootstrappingAttempts.get(), greaterThanOrEqualTo(5L));
236-
assertThat(deterministicTaskQueue.getCurrentTimeMillis(), greaterThanOrEqualTo(40000L));
229+
assertTrue(bootstrappingAttempted.get());
237230
}
238231

239232
public void testDoesNotBootstrapIfRequirementNotMet() {

0 commit comments

Comments
 (0)