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/25 07:59:53 UTC

[solr] branch branch_9x updated: SOLR-16446: Avoid redundant state.json update for PRS collection creation (#1093)

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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new d1458627d42 SOLR-16446: Avoid redundant state.json update for PRS collection creation (#1093)
d1458627d42 is described below

commit d1458627d4260f63ebe2738f365a7270b897f197
Author: patsonluk <pa...@users.noreply.github.com>
AuthorDate: Tue Oct 25 00:58:10 2022 -0700

    SOLR-16446: Avoid redundant state.json update for PRS collection creation (#1093)
---
 .../solr/cloud/api/collections/CreateCollectionCmd.java    | 14 +++++++++-----
 .../solr/common/cloud/PerReplicaStatesIntegrationTest.java | 13 ++++++-------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
index 8e15d25ea2b..2928f667386 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
@@ -330,8 +330,6 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {
           // update strategies
           ZkWriteCommand command =
               new SliceMutator(ccc.getSolrCloudManager()).addReplica(clusterState, props);
-          byte[] data = Utils.toJSON(Collections.singletonMap(collectionName, command.collection));
-          zkStateReader.getZkClient().setData(collectionPath, data, true);
           clusterState = clusterState.copyWith(collectionName, command.collection);
           newColl = command.collection;
         } else {
@@ -372,9 +370,15 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {
         coresToCreate.put(coreName, sreq);
       }
 
-      // PRS collections updated ZK state.json in the loop above. When Overseer is managing cluster
-      // state updates, need to tell it to refresh itself to know about the replicas and be able to
-      // execute nodes shard requests regarding the replicas.
+      // Update the state.json for PRS collection in a single operation
+      if (isPRS) {
+        byte[] data =
+            Utils.toJSON(
+                Collections.singletonMap(
+                    collectionName, clusterState.getCollection(collectionName)));
+        zkStateReader.getZkClient().setData(collectionPath, data, true);
+      }
+
       // Distributed updates don't need to do anything for PRS collections that wrote state.json
       // directly. For non PRS collections, distributed updates have to be executed if that's how
       // the cluster is configured
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
index dbefce3a36b..f5081ae0820 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
@@ -293,14 +293,13 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
           .setPerReplicaState(Boolean.TRUE)
           .process(cluster.getSolrClient());
       stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null, true);
-      // 0 from CreateCollectionCmd.create() and
-      // +1 each for each replica added CreateCollectionCmd.setData()
-      assertEquals(10, stat.getVersion());
+      // +1 after all replica are added with on state.json write to CreateCollectionCmd.setData()
+      assertEquals(1, stat.getVersion());
       // For each replica:
       // +1 for ZkController#preRegister, in ZkController#publish, direct write PRS to down
       // +2 for runLeaderProcess, flip the replica to leader
       // +2 for ZkController#register, in ZkController#publish, direct write PRS to active
-      // Hence 5 * 10 = 70. Take note that +1 for ADD, and +2 for all the UPDATE (remove the old PRS
+      // Hence 5 * 10 = 50. Take note that +1 for ADD, and +2 for all the UPDATE (remove the old PRS
       // and add new PRS entry)
       assertEquals(50, stat.getCversion());
 
@@ -340,9 +339,9 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
         j.stop();
         j.start(true);
         stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null, true);
-        // ensure restart does not update the state.json, after addReplica/deleteReplica its 10 + 2
-        // on state.json version
-        assertEquals(12, stat.getVersion());
+        // ensure restart does not update the state.json, after addReplica/deleteReplica, 2 more
+        // updates hence at version 3 on state.json version
+        assertEquals(3, stat.getVersion());
       }
     } finally {
       cluster.shutdown();