murblanc commented on code in PR #2039: URL: https://github.com/apache/solr/pull/2039#discussion_r1420468337
########## solr/solrj/src/java/org/apache/solr/common/cloud/ReplicaCount.java: ########## @@ -18,31 +18,92 @@ import java.util.Arrays; import java.util.EnumMap; +import java.util.EnumSet; import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; import org.apache.solr.common.SolrException; +import org.apache.solr.common.params.CollectionAdminParams; /** Tracks the number of replicas per replica type. This class is mutable. */ public final class ReplicaCount { private final EnumMap<Replica.Type, Integer> countByType; - public ReplicaCount(Integer nrtReplicas, Integer tlogReplicas, Integer pullReplicas) { + private ReplicaCount() { this.countByType = new EnumMap<>(Replica.Type.class); - put(Replica.Type.NRT, nrtReplicas); - put(Replica.Type.TLOG, tlogReplicas); - put(Replica.Type.PULL, pullReplicas); } public static ReplicaCount empty() { - return new ReplicaCount(null, null, null); + return new ReplicaCount(); } public static ReplicaCount of(Replica.Type type, Integer count) { - ReplicaCount replicaCount = empty(); + ReplicaCount replicaCount = new ReplicaCount(); replicaCount.put(type, count); return replicaCount; } + public static ReplicaCount of(Integer nrtReplicas, Integer tlogReplicas, Integer pullReplicas) { + ReplicaCount replicaCount = new ReplicaCount(); + replicaCount.put(Replica.Type.NRT, nrtReplicas); + replicaCount.put(Replica.Type.TLOG, tlogReplicas); + replicaCount.put(Replica.Type.PULL, pullReplicas); + return replicaCount; + } + + public static ReplicaCount fromMessage(ZkNodeProps message) { + return fromMessage(message, null); + } + + public static ReplicaCount fromMessage(ZkNodeProps message, DocCollection collection) { + return fromMessage(message, collection, null); + } + + public static ReplicaCount fromMessage( Review Comment: I think it would be useful to have two additional tests in `ReplicaCountTest` for `fromMessage`: 1. The fallback to collection default replication factor works when no replicas of the default type are specified (or no replicas at all are specified), 2. When no replicas are specified at all (message is empty), the default replica type count gets assigned correctly to the default replica type. -- 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