Skip to content

Commit

Permalink
Remove unused boolean return value
Browse files Browse the repository at this point in the history
ClusterState#assertConsistentRoutingNodes only returned true or threw an
AssertionError. We can simplify the logic by making it a static method that
initially checks whether assertions are enabled.
  • Loading branch information
williamrandolph committed Nov 28, 2023
1 parent 0a4a052 commit b8052ae
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions server/src/main/java/org/elasticsearch/cluster/ClusterState.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ChunkedToXContent;
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
import org.elasticsearch.core.Assertions;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.indices.SystemIndexDescriptor;
Expand Down Expand Up @@ -228,24 +229,19 @@ public ClusterState(
this.customs = customs;
this.wasReadFromDiff = wasReadFromDiff;
this.routingNodes = routingNodes;
assert assertConsistentRoutingNodes(routingTable, nodes, routingNodes);
assertConsistentRoutingNodes(routingTable, nodes, routingNodes);
this.minVersions = blocks.hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK)
? new CompatibilityVersions(TransportVersions.MINIMUM_COMPATIBLE, Map.of()) // empty map because cluster state is unknown
: CompatibilityVersions.minimumVersions(compatibilityVersions.values());
}

private static boolean assertConsistentRoutingNodes(
RoutingTable routingTable,
DiscoveryNodes nodes,
@Nullable RoutingNodes routingNodes
) {
if (routingNodes == null) {
return true;
private static void assertConsistentRoutingNodes(RoutingTable routingTable, DiscoveryNodes nodes, @Nullable RoutingNodes routingNodes) {
// calculating expected routing nodes may be costly, so we only do it when assertions are enabled
if (Assertions.ENABLED && Objects.nonNull(routingNodes)) {
final RoutingNodes expected = RoutingNodes.immutable(routingTable, nodes);
assert routingNodes.equals(expected)
: "RoutingNodes [" + routingNodes + "] are not consistent with this cluster state [" + expected + "]";
}
final RoutingNodes expected = RoutingNodes.immutable(routingTable, nodes);
assert routingNodes.equals(expected)
: "RoutingNodes [" + routingNodes + "] are not consistent with this cluster state [" + expected + "]";
return true;
}

public long term() {
Expand Down

0 comments on commit b8052ae

Please sign in to comment.