You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by no...@apache.org on 2022/10/13 19:54:35 UTC

[solr] 01/02: SOLR-16460: ClusterState.copyWith is buggy (#1070)

This is an automated email from the ASF dual-hosted git repository.

noble pushed a commit to branch branch_9_1
in repository https://gitbox.apache.org/repos/asf/solr.git

commit f00231c98de6890ca282de09fae6242fa9f35a67
Author: Noble Paul <no...@users.noreply.github.com>
AuthorDate: Fri Oct 14 05:59:30 2022 +1100

    SOLR-16460: ClusterState.copyWith is buggy (#1070)
---
 .../src/java/org/apache/solr/common/cloud/ClusterState.java    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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);
   }
 
   /**