From bbd4276b534f4949373c6596202c0877e19d3d2b Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 15 Oct 2021 16:39:14 +0200 Subject: [PATCH] fixed assertions --- .../java/org/elasticsearch/cluster/metadata/Metadata.java | 4 +--- .../org/elasticsearch/cluster/service/MasterService.java | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java index 072f8a8de1922..4f9e1f627e73d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java @@ -1587,9 +1587,7 @@ public Metadata build(boolean builtIndicesLookupEagerly) { SortedMap indicesLookup; if (previousIndicesLookup != null) { - // Can't compare the values, because IndexMetadata uses IndexMetadata, which are allowed to be updated. - // TODO: change IndexAbstraction's getIndices() and getWriteIndex() methods to return String instead of IndexMetadata - assert previousIndicesLookup.keySet().equals(buildIndicesLookup(dataStreamMetadata, indices).keySet()); + assert previousIndicesLookup.equals(buildIndicesLookup(dataStreamMetadata, indices)); indicesLookup = previousIndicesLookup; } else { if (builtIndicesLookupEagerly) { diff --git a/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java b/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java index 09a0c16eea74f..988b7c4bdfa98 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.ClusterStateTaskListener; import org.elasticsearch.cluster.coordination.ClusterStatePublisher; import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -52,6 +53,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.SortedMap; import java.util.concurrent.TimeUnit; import java.util.function.LongSupplier; import java.util.function.Supplier; @@ -368,6 +370,7 @@ private ClusterState patchVersions(ClusterState previousClusterState, ClusterTas if (previousClusterState != newClusterState) { // only the master controls the version numbers + final var previousIndicesLookup = newClusterState.metadata().getIndicesLookup(); Builder builder = incrementVersion(newClusterState); if (previousClusterState.routingTable() != newClusterState.routingTable()) { builder.routingTable(RoutingTable.builder(newClusterState.routingTable()) @@ -378,9 +381,9 @@ private ClusterState patchVersions(ClusterState previousClusterState, ClusterTas } newClusterState = builder.build(); + assert previousIndicesLookup == newClusterState.metadata().getIndicesLookup(); } - assert previousClusterState.metadata().getIndicesLookup() == newClusterState.metadata().getIndicesLookup(); return newClusterState; }