Skip to content

Commit 9d2bc20

Browse files
committed
Revert "Do not retry if bootstrapping throws an exception"
This reverts commit 2ff94a0.
1 parent 526acba commit 9d2bc20

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

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

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

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

21+
import org.elasticsearch.ElasticsearchException;
2122
import org.elasticsearch.Version;
2223
import org.elasticsearch.cluster.node.DiscoveryNode;
2324
import org.elasticsearch.cluster.node.DiscoveryNode.Role;
@@ -30,6 +31,7 @@
3031

3132
import java.util.Collections;
3233
import java.util.concurrent.atomic.AtomicBoolean;
34+
import java.util.concurrent.atomic.AtomicLong;
3335
import java.util.concurrent.atomic.AtomicReference;
3436
import java.util.function.Supplier;
3537
import java.util.stream.Collectors;
@@ -217,18 +219,23 @@ public void testDoesNotBootstrapsIfZen1NodesDiscovered() {
217219
deterministicTaskQueue.runAllTasks();
218220
}
219221

220-
public void testDoesNotRetryBootstrappingOnException() {
221-
final AtomicBoolean bootstrappingAttempted = new AtomicBoolean();
222+
public void testRetriesBootstrappingOnException() {
223+
224+
final AtomicLong bootstrappingAttempts = new AtomicLong();
222225
ClusterBootstrapService clusterBootstrapService = new ClusterBootstrapService(Settings.builder().putList(
223226
INITIAL_MASTER_NODES_SETTING.getKey(), localNode.getName(), otherNode1.getName(), otherNode2.getName()).build(),
224227
transportService, () -> Stream.of(otherNode1, otherNode2).collect(Collectors.toList()), vc -> {
225-
assertTrue(bootstrappingAttempted.compareAndSet(false, true));
228+
bootstrappingAttempts.incrementAndGet();
229+
if (bootstrappingAttempts.get() < 5L) {
230+
throw new ElasticsearchException("test");
231+
}
226232
});
227233

228234
transportService.start();
229235
clusterBootstrapService.onFoundPeersUpdated();
230236
deterministicTaskQueue.runAllTasks();
231-
assertTrue(bootstrappingAttempted.get());
237+
assertThat(bootstrappingAttempts.get(), greaterThanOrEqualTo(5L));
238+
assertThat(deterministicTaskQueue.getCurrentTimeMillis(), greaterThanOrEqualTo(40000L));
232239
}
233240

234241
public void testDoesNotBootstrapIfRequirementNotMet() {

0 commit comments

Comments
 (0)