Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16460: ClusterState.copyWith is buggy (#1070)

Noble Paul03703689f037
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
index 7d7e3c30a12..3a96b8b8dcd 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
@@ -83,7 +83,7 @@ public class ClusterState implements JSONWriter.Writable {
this.liveNodes = new HashSet<>(liveNodes.size());
this.liveNodes.addAll(liveNodes);
this.collectionStates = new LinkedHashMap<>(collectionStates);
- this.immutableCollectionStates = Collections.unmodifiableMap(collectionStates);
+ this.immutableCollectionStates = Collections.unmodifiableMap(this.collectionStates);
}
/**
@@ -94,13 +94,13 @@ public class ClusterState implements JSONWriter.Writable {
* @return the updated cluster state which preserves the current live nodes
*/
public ClusterState copyWith(String collectionName, DocCollection collection) {
- ClusterState result = new ClusterState(new LinkedHashMap<>(collectionStates), liveNodes);
+ LinkedHashMap<String, CollectionRef> collections = new LinkedHashMap<>(collectionStates);
if (collection == null) {
- result.collectionStates.remove(collectionName);
+ collections.remove(collectionName);
} else {
- result.collectionStates.put(collectionName, new CollectionRef(collection));
+ collections.put(collectionName, new CollectionRef(collection));
}
- return result;
+ return new ClusterState(collections, liveNodes);
}
/**