Apache Solr open-source search software
SOLR-16446: Avoid redundant state.json update for PRS collection creation (#1093)
patsonlukcc9a34e3484e
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.javaindex 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 strategiesZkWriteCommand 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 configureddiff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.javaindex 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();