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


##########
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:
   This succeeds: ```
   curl -X POST http://localhost:8983/api/collections -H 'Content-Type: 
application/json' -d '
     {
       "name": "techproducts_v2",
       "config": "_default",
       "numShards": 1,
       "createReplicas": false
     }'
   ```
   I run Solr with `docker run --rm -p 8983:8983 solr:9 -c`



-- 
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