Skip to content

Commit ac90145

Browse files
authored
Simplify InternalTestCluster.fullRestart (#50218)
With node ordinals gone, there's no longer a need for such a complicated full cluster restart procedure (as we can now uniquely associate nodes to data folders). Follow-up to #41652
1 parent 4f8d29e commit ac90145

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java

+9-29
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
5454
import org.elasticsearch.cluster.service.ClusterService;
5555
import org.elasticsearch.common.Nullable;
56+
import org.elasticsearch.common.Randomness;
5657
import org.elasticsearch.common.Strings;
5758
import org.elasticsearch.common.breaker.CircuitBreaker;
5859
import org.elasticsearch.common.component.LifecycleListener;
@@ -1729,50 +1730,29 @@ private void removeExclusions(Set<String> excludedNodeIds) {
17291730
public synchronized void fullRestart(RestartCallback callback) throws Exception {
17301731
int numNodesRestarted = 0;
17311732
final Settings[] newNodeSettings = new Settings[nextNodeId.get()];
1732-
Map<Set<DiscoveryNodeRole>, List<NodeAndClient>> nodesByRoles = new HashMap<>();
1733-
Set[] rolesOrderedByOriginalStartupOrder = new Set[nextNodeId.get()];
1734-
final int nodeCount = nodes.size();
1733+
final List<NodeAndClient> toStartAndPublish = new ArrayList<>(); // we want to start nodes in one go
17351734
for (NodeAndClient nodeAndClient : nodes.values()) {
17361735
callback.doAfterNodes(numNodesRestarted++, nodeAndClient.nodeClient());
17371736
logger.info("Stopping and resetting node [{}] ", nodeAndClient.name);
17381737
if (activeDisruptionScheme != null) {
17391738
activeDisruptionScheme.removeFromNode(nodeAndClient.name, this);
17401739
}
1741-
DiscoveryNode discoveryNode = getInstanceFromNode(ClusterService.class, nodeAndClient.node()).localNode();
17421740
final Settings newSettings = nodeAndClient.closeForRestart(callback);
17431741
newNodeSettings[nodeAndClient.nodeAndClientId()] = newSettings;
1744-
rolesOrderedByOriginalStartupOrder[nodeAndClient.nodeAndClientId()] = discoveryNode.getRoles();
1745-
nodesByRoles.computeIfAbsent(discoveryNode.getRoles(), k -> new ArrayList<>()).add(nodeAndClient);
1742+
toStartAndPublish.add(nodeAndClient);
17461743
}
17471744

17481745
callback.onAllNodesStopped();
17491746

1750-
assert nodesByRoles.values().stream().mapToInt(List::size).sum() == nodeCount;
1747+
// randomize start up order
1748+
Randomness.shuffle(toStartAndPublish);
17511749

1752-
// randomize start up order, but making sure that:
1753-
// 1) A data folder that was assigned to a data node will stay so
1754-
// 2) Data nodes will get the same node lock ordinal range, so custom index paths (where the ordinal is used)
1755-
// will still belong to data nodes
1756-
for (List<NodeAndClient> sameRoleNodes : nodesByRoles.values()) {
1757-
Collections.shuffle(sameRoleNodes, random);
1758-
}
1759-
final List<NodeAndClient> startUpOrder = new ArrayList<>();
1760-
for (Set roles : rolesOrderedByOriginalStartupOrder) {
1761-
if (roles == null) {
1762-
// if some nodes were stopped, we want have a role for that ordinal
1763-
continue;
1764-
}
1765-
final List<NodeAndClient> nodesByRole = nodesByRoles.get(roles);
1766-
startUpOrder.add(nodesByRole.remove(0));
1750+
for (NodeAndClient nodeAndClient : toStartAndPublish) {
1751+
logger.info("recreating node [{}] ", nodeAndClient.name);
1752+
nodeAndClient.recreateNode(newNodeSettings[nodeAndClient.nodeAndClientId()], () -> rebuildUnicastHostFiles(toStartAndPublish));
17671753
}
1768-
assert nodesByRoles.values().stream().mapToInt(List::size).sum() == 0;
17691754

1770-
for (NodeAndClient nodeAndClient : startUpOrder) {
1771-
logger.info("creating node [{}] ", nodeAndClient.name);
1772-
nodeAndClient.recreateNode(newNodeSettings[nodeAndClient.nodeAndClientId()], () -> rebuildUnicastHostFiles(startUpOrder));
1773-
}
1774-
1775-
startAndPublishNodesAndClients(startUpOrder);
1755+
startAndPublishNodesAndClients(toStartAndPublish);
17761756

17771757
if (callback.validateClusterForming()) {
17781758
validateClusterFormed();

0 commit comments

Comments
 (0)