pvcnt commented on code in PR #2039:
URL: https://github.com/apache/solr/pull/2039#discussion_r1412177582


##########
solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java:
##########
@@ -590,12 +589,22 @@ public static List<String> populateShardNames(ZkNodeProps 
message, String router
     return shardNames;
   }
 
-  private static ReplicaCount getNumReplicas(ZkNodeProps message) {
-    int numTlogReplicas = message.getInt(TLOG_REPLICAS, 0);
-    int numNrtReplicas =
-        message.getInt(
-            NRT_REPLICAS, message.getInt(REPLICATION_FACTOR, numTlogReplicas > 
0 ? 0 : 1));
-    return new ReplicaCount(numNrtReplicas, numTlogReplicas, 
message.getInt(PULL_REPLICAS, 0));
+  private ReplicaCount getNumReplicas(ZkNodeProps message) {
+    ReplicaCount numReplicas = ReplicaCount.fromMessage(message);
+    int numLeaderEligibleReplicas = 
numReplicas.count(leaderEligibleReplicaTypes);
+    if (numLeaderEligibleReplicas == 0 && 
!numReplicas.contains(Replica.Type.defaultType())) {
+      // Ensure that there is at least one replica that can become leader if 
the user did
+      // not force a replica count.
+      numReplicas.put(Replica.Type.defaultType(), 1);
+    } else if (numLeaderEligibleReplicas == 0) {
+      // This can still fail if the user manually forced "0" replica counts.

Review Comment:
   It may be a bug (what is the purpose of validating the number of replicas if 
not creating any replicas?), but the goal of this PR is not to change this 
behaviour.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to