pvcnt commented on code in PR #2039: URL: https://github.com/apache/solr/pull/2039#discussion_r1411071522
########## 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: I don't think it is valid to create a collection with 0 replicas. I went back to the commit before I introduced `ReplicaCount`, and I see [the following](https://github.com/apache/solr/blob/8b9954317690428b13e1c6c4ed1dbdb743ab389b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java#L580): ```java int numTlogReplicas = message.getInt(TLOG_REPLICAS, 0); int numNrtReplicas = message.getInt( NRT_REPLICAS, message.getInt(REPLICATION_FACTOR, numTlogReplicas > 0 ? 0 : 1)); if (numNrtReplicas + numTlogReplicas <= 0) { throw new SolrException( ErrorCode.BAD_REQUEST, NRT_REPLICAS + " + " + TLOG_REPLICAS + " must be greater than 0"); } ``` -- 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