Skip to content

Commit eadc797

Browse files
committed
Reject duplicate requirements early
1 parent c0d62af commit eadc797

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import java.util.Collections;
3636
import java.util.HashSet;
37+
import java.util.LinkedHashSet;
3738
import java.util.List;
3839
import java.util.Random;
3940
import java.util.Set;
@@ -61,7 +62,7 @@ public class ClusterBootstrapService {
6162
static final String BOOTSTRAP_PLACEHOLDER_PREFIX = "{bootstrap-placeholder}";
6263

6364
private static final Logger logger = LogManager.getLogger(ClusterBootstrapService.class);
64-
private final List<String> initialMasterNodes;
65+
private final Set<String> initialMasterNodes;
6566
@Nullable // null if discoveryIsConfigured()
6667
private final TimeValue unconfiguredBootstrapTimeout;
6768
private final TransportService transportService;
@@ -74,7 +75,13 @@ public class ClusterBootstrapService {
7475
public ClusterBootstrapService(Settings settings, TransportService transportService, Random random,
7576
Supplier<Iterable<DiscoveryNode>> discoveredNodesSupplier, BooleanSupplier isBootstrappedSupplier,
7677
Consumer<VotingConfiguration> votingConfigurationConsumer) {
77-
initialMasterNodes = INITIAL_MASTER_NODES_SETTING.get(settings);
78+
final List<String> initialMasterNodesList = INITIAL_MASTER_NODES_SETTING.get(settings);
79+
this.initialMasterNodes = new LinkedHashSet<>(initialMasterNodesList);
80+
if (this.initialMasterNodes.size() != initialMasterNodesList.size()) {
81+
throw new IllegalArgumentException(
82+
"setting [" + INITIAL_MASTER_NODES_SETTING.getKey() + "] contains duplicates: " + initialMasterNodesList);
83+
}
84+
7885
unconfiguredBootstrapTimeout = discoveryIsConfigured(settings) ? null : UNCONFIGURED_BOOTSTRAP_TIMEOUT_SETTING.get(settings);
7986
this.transportService = transportService;
8087
this.random = random;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ public void testDoesNothingByDefaultIfZen1NodesDiscovered() {
164164
deterministicTaskQueue.runAllTasks();
165165
}
166166

167+
168+
public void testThrowsExceptionOnDuplicates() {
169+
final IllegalArgumentException illegalArgumentException = expectThrows(IllegalArgumentException.class, () -> {
170+
new ClusterBootstrapService(builder().putList(
171+
INITIAL_MASTER_NODES_SETTING.getKey(), "duplicate-requirement", "duplicate-requirement").build(),
172+
transportService, random(), Collections::emptyList, () -> false, vc -> {
173+
throw new AssertionError("should not be called");
174+
});
175+
});
176+
177+
assertThat(illegalArgumentException.getMessage(), containsString(INITIAL_MASTER_NODES_SETTING.getKey()));
178+
assertThat(illegalArgumentException.getMessage(), containsString("duplicate-requirement"));
179+
}
180+
167181
public void testBootstrapsOnDiscoveryOfAllRequiredNodes() {
168182
final AtomicBoolean bootstrapped = new AtomicBoolean();
169183

0 commit comments

Comments
 (0)