Skip to content

Commit 2faf2d1

Browse files
committed
Move invariant in the assertion, so it's not run in production.
1 parent c2fc4d8 commit 2faf2d1

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.cluster.node.DiscoveryNode;
1313
import org.elasticsearch.common.util.Maps;
14-
import org.elasticsearch.common.util.set.Sets;
1514
import org.elasticsearch.core.Nullable;
1615
import org.elasticsearch.index.Index;
1716
import org.elasticsearch.index.shard.ShardId;
@@ -26,7 +25,6 @@
2625
import java.util.Objects;
2726
import java.util.Set;
2827
import java.util.function.Predicate;
29-
import java.util.stream.Collectors;
3028
import java.util.stream.Stream;
3129

3230
/**
@@ -49,9 +47,6 @@ public class RoutingNode implements Iterable<ShardRouting> {
4947
private final LinkedHashSet<ShardRouting> startedShards;
5048

5149
private final Map<Index, Set<ShardRouting>> shardsByIndex;
52-
53-
private final Set<String> indexUuids;
54-
5550
/**
5651
* @param nodeId node id of this routing node
5752
* @param node discovery node for this routing node
@@ -66,7 +61,6 @@ public class RoutingNode implements Iterable<ShardRouting> {
6661
this.initializingShards = new LinkedHashSet<>();
6762
this.startedShards = new LinkedHashSet<>();
6863
this.shardsByIndex = Maps.newHashMapWithExpectedSize(sizeGuess);
69-
this.indexUuids = Sets.newHashSetWithExpectedSize(sizeGuess);
7064
assert invariant();
7165
}
7266

@@ -78,7 +72,6 @@ private RoutingNode(RoutingNode original) {
7872
this.initializingShards = new LinkedHashSet<>(original.initializingShards);
7973
this.startedShards = new LinkedHashSet<>(original.startedShards);
8074
this.shardsByIndex = Maps.copyOf(original.shardsByIndex, HashSet::new);
81-
this.indexUuids = original.shardsByIndex.keySet().stream().map(Index::getUUID).collect(Collectors.toSet());
8275
assert invariant();
8376
}
8477

@@ -110,10 +103,6 @@ public boolean hasIndex(Index index) {
110103
return shardsByIndex.containsKey(index);
111104
}
112105

113-
public boolean hasIndex(String indexUuid) {
114-
return indexUuids.contains(indexUuid);
115-
}
116-
117106
/**
118107
* Get the id of this node
119108
* @return id of the node
@@ -167,7 +156,6 @@ private void addInternal(ShardRouting shard, boolean validate) {
167156
startedShards.add(shard);
168157
}
169158
shardsByIndex.computeIfAbsent(shard.index(), k -> new HashSet<>()).add(shard);
170-
indexUuids.add(shard.index().getUUID());
171159
assert validate == false || invariant();
172160
}
173161

@@ -220,7 +208,6 @@ void remove(ShardRouting shard) {
220208
byIndex.remove(shard);
221209
if (byIndex.isEmpty()) {
222210
shardsByIndex.remove(shard.index());
223-
indexUuids.remove(shard.index().getUUID());
224211
}
225212
assert invariant();
226213
}
@@ -355,7 +342,7 @@ boolean invariant() {
355342
assert relocatingShards.size() == shardRoutingsRelocating.size() && relocatingShards.containsAll(shardRoutingsRelocating);
356343
assert startedShards.size() == shardRoutingsStarted.size() && startedShards.containsAll(shardRoutingsStarted);
357344
assert shardRoutingsByIndex.equals(shardsByIndex);
358-
assert shardsByIndex.size() == indexUuids.size();
345+
assert shardsByIndex.size() == shardsByIndex.keySet().stream().map(Index::getUUID).distinct().count();
359346

360347
return true;
361348
}

0 commit comments

Comments
 (0)