Apache Solr open-source search software
SOLR-16995: Associate with each replica type a property for "numReplicas" (#2039)
Vincent P10c09d02ac94
diff --git a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.javaindex c67ad066a86..e1768e0cd37 100644--- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java+++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java@@ -17,12 +17,11 @@package org.apache.solr.cloud;import java.lang.invoke.MethodHandles;-import java.util.Arrays;import java.util.EnumSet;import java.util.concurrent.Future;import java.util.concurrent.TimeUnit;-import java.util.stream.Collectors;import org.apache.lucene.search.MatchAllDocsQuery;+import org.apache.solr.cloud.api.collections.CollectionHandlingUtils;import org.apache.solr.cloud.overseer.OverseerAction;import org.apache.solr.common.MapWriter;import org.apache.solr.common.SolrException;@@ -48,11 +47,12 @@ import org.slf4j.LoggerFactory;final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());+ private static final EnumSet<Replica.Type> leaderEligibleReplicaTypes =+ CollectionHandlingUtils.leaderEligibleReplicaTypes();private final CoreContainer cc;private final SyncStrategy syncStrategy;private final DistributedClusterStateUpdater distributedClusterStateUpdater;- private final EnumSet<Replica.Type> leaderEligibleReplicaTypes;private volatile boolean isClosed = false;@@ -68,10 +68,6 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {this.cc = cc;this.syncStrategy = new SyncStrategy(cc);this.distributedClusterStateUpdater = zkController.getDistributedClusterStateUpdater();- leaderEligibleReplicaTypes =- Arrays.stream(Replica.Type.values())- .filter(t -> t.leaderEligible)- .collect(Collectors.toCollection(() -> EnumSet.noneOf(Replica.Type.class)));}@Overridediff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.javaindex e7c66689874..b7ed4954fbf 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java@@ -21,10 +21,7 @@ import static org.apache.solr.cloud.api.collections.CollectionHandlingUtils.CREAimport static org.apache.solr.cloud.api.collections.CollectionHandlingUtils.SKIP_CREATE_REPLICA_IN_CLUSTER_STATE;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;-import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;import static org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASES;import static org.apache.solr.common.params.CollectionParams.CollectionAction.ADDREPLICA;@@ -38,7 +35,6 @@ import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.List;-import java.util.Locale;import java.util.Map;import java.util.concurrent.TimeUnit;import java.util.stream.Collectors;@@ -135,19 +131,7 @@ public class AddReplicaCmd implements CollApiCmds.CollectionApiCommand {int timeout = message.getInt(TIMEOUT, 10 * 60); // 10 minutesboolean parallel = message.getBool("parallel", false);- ReplicaCount numReplicas =- new ReplicaCount(- message.getInt(NRT_REPLICAS, 0),- message.getInt(TLOG_REPLICAS, 0),- message.getInt(PULL_REPLICAS, 0));- if (numReplicas.total() <= 0) {- Replica.Type replicaType =- Replica.Type.valueOf(- message- .getStr(ZkStateReader.REPLICA_TYPE, Replica.Type.NRT.name())- .toUpperCase(Locale.ROOT));- numReplicas.increment(replicaType);- }+ ReplicaCount numReplicas = ReplicaCount.fromMessage(message, null, 1);int totalReplicas = numReplicas.total();if (totalReplicas > 1) {@@ -450,7 +434,7 @@ public class AddReplicaCmd implements CollApiCmds.CollectionApiCommand {// the same node, but we've got to accommodate.positions = new ArrayList<>(totalReplicas);int i = 0;- for (Replica.Type type : Replica.Type.values()) {+ for (Replica.Type type : numReplicas.keySet()) {for (int j = 0; j < numReplicas.get(type); j++) {positions.add(new ReplicaPosition(collectionName, sliceName, i++, type, node));}diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.javaindex 393e164dd4a..f2462430f48 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CollectionHandlingUtils.java@@ -28,6 +28,7 @@ import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;+import java.util.EnumSet;import java.util.List;import java.util.Map;import java.util.Random;@@ -35,6 +36,7 @@ import java.util.Set;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.TimeUnit;import java.util.concurrent.TimeoutException;+import java.util.stream.Collectors;import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.SolrResponse;import org.apache.solr.client.solrj.SolrServerException;@@ -107,20 +109,24 @@ public class CollectionHandlingUtils {// Immutable Maps are null-hostile, so build our ownpublic static final Map<String, Object> COLLECTION_PROPS_AND_DEFAULTS =- Collections.unmodifiableMap(- Utils.makeMap(- CollectionStateProps.DOC_ROUTER,- DocRouter.DEFAULT_NAME,- CollectionStateProps.REPLICATION_FACTOR,- "1",- CollectionStateProps.NRT_REPLICAS,- "1",- CollectionStateProps.TLOG_REPLICAS,- "0",- CollectionStateProps.PER_REPLICA_STATE,- null,- CollectionStateProps.PULL_REPLICAS,- "0"));+ Collections.unmodifiableMap(makeCollectionPropsAndDefaults());++ private static Map<String, Object> makeCollectionPropsAndDefaults() {+ Map<String, Object> propsAndDefaults =+ Utils.makeMap(+ CollectionStateProps.DOC_ROUTER,+ (Object) DocRouter.DEFAULT_NAME,+ CollectionStateProps.REPLICATION_FACTOR,+ "1",+ CollectionStateProps.PER_REPLICA_STATE,+ null);+ for (Replica.Type replicaType : Replica.Type.values()) {+ propsAndDefaults.put(+ replicaType.numReplicasPropertyName,+ replicaType == Replica.Type.defaultType() ? "1" : "0");+ }+ return propsAndDefaults;+ }public static final Random RANDOM;@@ -135,6 +141,20 @@ public class CollectionHandlingUtils {}}+ /** Returns names of properties that are used to specify a number of replicas of a given type. */+ public static Set<String> numReplicasProperties() {+ return Arrays.stream(Replica.Type.values())+ .map(t -> t.numReplicasPropertyName)+ .collect(Collectors.toSet());+ }++ /** Returns replica types that are eligible to be leader. */+ public static EnumSet<Replica.Type> leaderEligibleReplicaTypes() {+ return Arrays.stream(Replica.Type.values())+ .filter(t -> t.leaderEligible)+ .collect(Collectors.toCollection(() -> EnumSet.noneOf(Replica.Type.class)));+ }+static boolean waitForCoreNodeGone(String collectionName,String shard,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 a00b01b2370..020146cfdc7 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@@ -17,10 +17,6 @@package org.apache.solr.cloud.api.collections;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;-import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;-import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;-import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.ALIAS;import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;import static org.apache.solr.common.params.CollectionParams.CollectionAction.ADDREPLICA;@@ -139,7 +135,6 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {// fail fast if parameters are wrong or incompleteList<String> shardNames = populateShardNames(message, router);ReplicaCount numReplicas = getNumReplicas(message);- numReplicas.validate();DocCollection newColl = null;final String collectionPath = DocCollection.getCollectionPath(collectionName);@@ -590,12 +585,22 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {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);+ boolean hasLeaderEligibleReplica = numReplicas.hasLeaderReplica();+ if (!hasLeaderEligibleReplica && !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 (!hasLeaderEligibleReplica) {+ // This can still fail if the user manually forced "0" replica counts.+ throw new SolrException(+ SolrException.ErrorCode.BAD_REQUEST,+ "Unexpected number of replicas ("+ + numReplicas+ + "), there must be at least one leader-eligible replica");+ }+ return numReplicas;}String getConfigName(String coll, ZkNodeProps message) throws IOException {diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateShardCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateShardCmd.javaindex 495f6856bc7..b76250cfd8d 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateShardCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateShardCmd.java@@ -17,28 +17,22 @@package org.apache.solr.cloud.api.collections;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;-import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;-import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASES;import static org.apache.solr.common.params.CommonAdminParams.ASYNC;import java.lang.invoke.MethodHandles;-import java.util.HashMap;import java.util.Map;import org.apache.solr.cloud.DistributedClusterStateUpdater;import org.apache.solr.common.SolrException;import org.apache.solr.common.cloud.ClusterState;import org.apache.solr.common.cloud.DocCollection;-import org.apache.solr.common.cloud.Replica;import org.apache.solr.common.cloud.ReplicaCount;import org.apache.solr.common.cloud.ZkNodeProps;-import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.params.CommonAdminParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SimpleOrderedMap;+import org.apache.solr.common.util.Utils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -72,8 +66,14 @@ public class CreateShardCmd implements CollApiCmds.CollectionApiCommand {}DocCollection collection = clusterState.getCollection(collectionName);- ReplicaCount numReplicas = getNumReplicas(collection, message);- numReplicas.validate();+ ReplicaCount numReplicas = ReplicaCount.fromMessage(message, collection, 1);+ if (!numReplicas.hasLeaderReplica()) {+ throw new SolrException(+ SolrException.ErrorCode.BAD_REQUEST,+ "Unexpected number of replicas ("+ + numReplicas+ + "), there must be at least one leader-eligible replica");+ }if (ccc.getDistributedClusterStateUpdater().isDistributedStateUpdate()) {// The message has been crafted by CollectionsHandler.CollectionOperation.CREATESHARD_OP and@@ -97,33 +97,28 @@ public class CreateShardCmd implements CollApiCmds.CollectionApiCommand {CollectionHandlingUtils.waitForNewShard(collectionName, sliceName, ccc.getZkStateReader());String async = message.getStr(ASYNC);- ZkNodeProps addReplicasProps =- new ZkNodeProps(+ Map<String, Object> addReplicasProps =+ Utils.makeMap(COLLECTION_PROP,- collectionName,+ (Object) collectionName,SHARD_ID_PROP,sliceName,- ZkStateReader.NRT_REPLICAS,- String.valueOf(numReplicas.get(Replica.Type.NRT)),- ZkStateReader.TLOG_REPLICAS,- String.valueOf(numReplicas.get(Replica.Type.TLOG)),- ZkStateReader.PULL_REPLICAS,- String.valueOf(numReplicas.get(Replica.Type.PULL)),CollectionHandlingUtils.CREATE_NODE_SET,message.getStr(CollectionHandlingUtils.CREATE_NODE_SET),CommonAdminParams.WAIT_FOR_FINAL_STATE,Boolean.toString(waitForFinalState));+ numReplicas.writeProps(addReplicasProps);- Map<String, Object> propertyParams = new HashMap<>();- CollectionHandlingUtils.addPropertyParams(message, propertyParams);- addReplicasProps = addReplicasProps.plus(propertyParams);- if (async != null) addReplicasProps.getProperties().put(ASYNC, async);+ CollectionHandlingUtils.addPropertyParams(message, addReplicasProps);+ if (async != null) {+ addReplicasProps.put(ASYNC, async);+ }final NamedList<Object> addResult = new NamedList<>();try {new AddReplicaCmd(ccc).addReplica(clusterState,- addReplicasProps,+ new ZkNodeProps(addReplicasProps),addResult,() -> {@SuppressWarnings("unchecked")@@ -160,15 +155,4 @@ public class CreateShardCmd implements CollApiCmds.CollectionApiCommand {log.info("Finished create command on all shards for collection: {}", collectionName);}-- private static ReplicaCount getNumReplicas(DocCollection collection, ZkNodeProps message) {- return new ReplicaCount(- message.getInt(- NRT_REPLICAS,- message.getInt(- REPLICATION_FACTOR,- collection.getInt(NRT_REPLICAS, collection.getInt(REPLICATION_FACTOR, 1)))),- message.getInt(PULL_REPLICAS, collection.getInt(PULL_REPLICAS, 0)),- message.getInt(TLOG_REPLICAS, collection.getInt(TLOG_REPLICAS, 0)));- }}diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.javaindex 4ee59d13ca9..cdcb3c27449 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java@@ -18,7 +18,6 @@package org.apache.solr.cloud.api.collections;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;import static org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASES;import static org.apache.solr.common.params.CollectionParams.CollectionAction.ADDREPLICA;@@ -308,7 +307,7 @@ public class MigrateCmd implements CollApiCmds.CollectionApiCommand {CREATE.toLower(),NAME,tempSourceCollectionName,- NRT_REPLICAS,+ Replica.Type.defaultType().numReplicasPropertyName,1,CollectionHandlingUtils.NUM_SLICES,1,@@ -394,7 +393,7 @@ public class MigrateCmd implements CollApiCmds.CollectionApiCommand {ccc.getSolrCloudManager().getDistribStateManager(),zkStateReader.getClusterState().getCollection(tempSourceCollectionName),tempSourceSlice.getName(),- Replica.Type.NRT);+ Replica.Type.defaultType());props = new HashMap<>();props.put(Overseer.QUEUE_OPERATION, ADDREPLICA.toLower());props.put(COLLECTION_PROP, tempSourceCollectionName);diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.javaindex c4ffc78a5bf..8a083d375cc 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/ReindexCollectionCmd.java@@ -21,7 +21,6 @@ import static org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASESimport com.google.common.annotations.VisibleForTesting;import java.lang.invoke.MethodHandles;-import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Locale;@@ -48,6 +47,7 @@ import org.apache.solr.common.cloud.ClusterState;import org.apache.solr.common.cloud.DocCollection;import org.apache.solr.common.cloud.DocRouter;import org.apache.solr.common.cloud.Replica;+import org.apache.solr.common.cloud.ReplicaCount;import org.apache.solr.common.cloud.ZkNodeProps;import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.params.CollectionAdminParams;@@ -104,16 +104,16 @@ public class ReindexCollectionCmd implements CollApiCmds.CollectionApiCommand {public static final String PHASE = "phase";private static final List<String> COLLECTION_PARAMS =- Arrays.asList(- ZkStateReader.CONFIGNAME_PROP,- ZkStateReader.NUM_SHARDS_PROP,- ZkStateReader.NRT_REPLICAS,- ZkStateReader.PULL_REPLICAS,- ZkStateReader.TLOG_REPLICAS,- ZkStateReader.REPLICATION_FACTOR,- "shards",- CollectionAdminParams.CREATE_NODE_SET_PARAM,- CollectionAdminParams.CREATE_NODE_SET_SHUFFLE_PARAM);+ Stream.concat(+ CollectionHandlingUtils.numReplicasProperties().stream(),+ Stream.of(+ ZkStateReader.CONFIGNAME_PROP,+ ZkStateReader.NUM_SHARDS_PROP,+ ZkStateReader.REPLICATION_FACTOR,+ "shards",+ CollectionAdminParams.CREATE_NODE_SET_PARAM,+ CollectionAdminParams.CREATE_NODE_SET_SHUFFLE_PARAM))+ .collect(Collectors.toUnmodifiableList());private final CollectionCommandContext ccc;@@ -249,9 +249,7 @@ public class ReindexCollectionCmd implements CollApiCmds.CollectionApiCommand {String query = message.getStr(CommonParams.Q, "*:*");String fl = message.getStr(CommonParams.FL, "*");Integer rf = message.getInt(ZkStateReader.REPLICATION_FACTOR, coll.getReplicationFactor());- Integer numNrt = message.getInt(ZkStateReader.NRT_REPLICAS, coll.getNumNrtReplicas());- Integer numTlog = message.getInt(ZkStateReader.TLOG_REPLICAS, coll.getNumTlogReplicas());- Integer numPull = message.getInt(ZkStateReader.PULL_REPLICAS, coll.getNumPullReplicas());+ ReplicaCount numReplicas = ReplicaCount.fromMessage(message, coll);int numShards = message.getInt(ZkStateReader.NUM_SHARDS_PROP, coll.getActiveSlices().size());DocRouter router = coll.getRouter();if (router == null) {@@ -338,15 +336,7 @@ public class ReindexCollectionCmd implements CollApiCmds.CollectionApiCommand {if (rf != null) {propMap.put(ZkStateReader.REPLICATION_FACTOR, rf);}- if (numNrt != null) {- propMap.put(ZkStateReader.NRT_REPLICAS, numNrt);- }- if (numTlog != null) {- propMap.put(ZkStateReader.TLOG_REPLICAS, numTlog);- }- if (numPull != null) {- propMap.put(ZkStateReader.PULL_REPLICAS, numPull);- }+ numReplicas.writeProps(propMap);// create the target collectioncmd = new ZkNodeProps(propMap);cmdResults = new NamedList<>();diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.javaindex c3bc1a19de0..b774663b1e2 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java@@ -18,12 +18,9 @@package org.apache.solr.cloud.api.collections;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;-import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;import static org.apache.solr.common.cloud.ZkStateReader.REPLICA_TYPE;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;import static org.apache.solr.common.params.CollectionParams.CollectionAction.CREATE;import static org.apache.solr.common.params.CollectionParams.CollectionAction.CREATESHARD;import static org.apache.solr.common.params.CommonAdminParams.ASYNC;@@ -139,11 +136,6 @@ public class RestoreCmd implements CollApiCmds.CollectionApiCommand {new NamedList<>(), shardHandler, true, "Could not restore core");}- private int getInt(ZkNodeProps message, String propertyName, Integer count, int defaultValue) {- Integer value = message.getInt(propertyName, count);- return value != null ? value : defaultValue;- }-/** Encapsulates the parsing and access for common parameters restore parameters and values */private static class RestoreContext implements Closeable {@@ -226,22 +218,7 @@ public class RestoreCmd implements CollApiCmds.CollectionApiCommand {private RestoreOnANewCollection(ZkNodeProps message, DocCollection backupCollectionState) {this.message = message;-- int numNrtReplicas;- if (message.get(REPLICATION_FACTOR) != null) {- numNrtReplicas = message.getInt(REPLICATION_FACTOR, 0);- } else if (message.get(NRT_REPLICAS) != null) {- numNrtReplicas = message.getInt(NRT_REPLICAS, 0);- } else {- // replicationFactor and nrtReplicas is always in sync after SOLR-11676- // pick from cluster state of the backed up collection- numNrtReplicas = backupCollectionState.getReplicationFactor();- }- this.numReplicas =- new ReplicaCount(- numNrtReplicas,- getInt(message, TLOG_REPLICAS, backupCollectionState.getNumTlogReplicas(), 0),- getInt(message, PULL_REPLICAS, backupCollectionState.getNumPullReplicas(), 0));+ this.numReplicas = ReplicaCount.fromMessage(message, backupCollectionState);}public void process(NamedList<Object> results, RestoreContext rc) throws Exception {@@ -341,10 +318,8 @@ public class RestoreCmd implements CollApiCmds.CollectionApiCommand {propMap.put(Overseer.QUEUE_OPERATION, CREATE.toString());// mostly true. Prevents autoCreated=true in the collection state.propMap.put("fromApi", "true");- propMap.put(REPLICATION_FACTOR, numReplicas.get(Replica.Type.NRT));- propMap.put(NRT_REPLICAS, numReplicas.get(Replica.Type.NRT));- propMap.put(TLOG_REPLICAS, numReplicas.get(Replica.Type.TLOG));- propMap.put(PULL_REPLICAS, numReplicas.get(Replica.Type.PULL));+ propMap.put(REPLICATION_FACTOR, numReplicas.get(Replica.Type.defaultType()));+ numReplicas.writeProps(propMap);// inherit settings from input API, defaulting to the backup's setting. Ex: replicationFactorfor (String collProp : CollectionHandlingUtils.COLLECTION_PROPS_AND_DEFAULTS.keySet()) {@@ -550,7 +525,7 @@ public class RestoreCmd implements CollApiCmds.CollectionApiCommand {for (int i = 1; i < totalReplicasPerShard; i++) {Replica.Type typeToCreate = null;- for (Replica.Type type : Replica.Type.values()) {+ for (Replica.Type type : numReplicas.keySet()) {if (createdReplicas.get(type) < numReplicas.get(type)) {createdReplicas.increment(type);typeToCreate = type;diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java b/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.javaindex 318dd595d31..088c4f8fed7 100644--- a/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java@@ -18,7 +18,6 @@ package org.apache.solr.cloud.overseer;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;import static org.apache.solr.common.cloud.ZkStateReader.CONFIGNAME_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;@@ -149,7 +148,8 @@ public class CollectionMutator {}// SOLR-11676 : keep NRT_REPLICAS and REPLICATION_FACTOR in syncif (prop.equals(REPLICATION_FACTOR)) {- props.put(NRT_REPLICAS, message.get(REPLICATION_FACTOR));+ props.put(+ Replica.Type.defaultType().numReplicasPropertyName, message.get(REPLICATION_FACTOR));}}}diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/PlacementRequestImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/PlacementRequestImpl.javaindex f101046803d..78b5a2bf647 100644--- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/PlacementRequestImpl.java+++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/PlacementRequestImpl.java@@ -33,21 +33,6 @@ public class PlacementRequestImpl implements PlacementRequest {private final Set<Node> targetNodes;private final ReplicaCount numReplicas;- @Deprecated- public PlacementRequestImpl(- SolrCollection solrCollection,- Set<String> shardNames,- Set<Node> targetNodes,- int countNrtReplicas,- int countTlogReplicas,- int countPullReplicas) {- this(- solrCollection,- shardNames,- targetNodes,- new ReplicaCount(countNrtReplicas, countTlogReplicas, countPullReplicas));- }-public PlacementRequestImpl(SolrCollection solrCollection,Set<String> shardNames,diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.javaindex 50087cdf1a5..485670a4421 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java@@ -29,14 +29,11 @@ import static org.apache.solr.cloud.api.collections.CollectionHandlingUtils.REQUimport static org.apache.solr.cloud.api.collections.CollectionHandlingUtils.SHARD_UNIQUE;import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.PROPERTY_PROP;import static org.apache.solr.common.cloud.ZkStateReader.PROPERTY_VALUE_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;import static org.apache.solr.common.cloud.ZkStateReader.REPLICA_PROP;import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;-import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.COLLECTION;import static org.apache.solr.common.params.CollectionAdminParams.CREATE_NODE_SET_PARAM;import static org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASES;@@ -139,6 +136,7 @@ import org.apache.solr.cloud.OverseerTaskQueue;import org.apache.solr.cloud.OverseerTaskQueue.QueueEvent;import org.apache.solr.cloud.ZkController;import org.apache.solr.cloud.ZkController.NotInClusterStateException;+import org.apache.solr.cloud.api.collections.CollectionHandlingUtils;import org.apache.solr.cloud.api.collections.DistributedCollectionConfigSetCommandRunner;import org.apache.solr.cloud.api.collections.ReindexCollectionCmd;import org.apache.solr.common.SolrException;@@ -589,9 +587,6 @@ public class CollectionsHandler extends RequestHandlerBase implements PermissionReindexCollectionCmd.TARGET,ZkStateReader.CONFIGNAME_PROP,NUM_SLICES,- NRT_REPLICAS,- PULL_REPLICAS,- TLOG_REPLICAS,REPLICATION_FACTOR,CREATE_NODE_SET,CREATE_NODE_SET_SHUFFLE,@@ -600,6 +595,7 @@ public class CollectionsHandler extends RequestHandlerBase implements PermissionCommonParams.Q,CommonParams.FL,FOLLOW_ALIASES);+ copy(req.getParams(), m, CollectionHandlingUtils.numReplicasProperties());if (req.getParams().get("collection." + ZkStateReader.CONFIGNAME_PROP) != null) {m.put(ZkStateReader.CONFIGNAME_PROP,@@ -1057,7 +1053,7 @@ public class CollectionsHandler extends RequestHandlerBase implements PermissionDocCollection.verifyProp(m, prop);}if (m.get(REPLICATION_FACTOR) != null) {- m.put(NRT_REPLICAS, m.get(REPLICATION_FACTOR));+ m.put(Replica.Type.defaultType().numReplicasPropertyName, m.get(REPLICATION_FACTOR));}return m;}),diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RestoreCollectionAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RestoreCollectionAPI.javaindex b603d8d13f7..8b48b5288c6 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/api/RestoreCollectionAPI.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RestoreCollectionAPI.java@@ -24,11 +24,8 @@ import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;import static org.apache.solr.common.params.CollectionAdminParams.CREATE_NODE_SET_PARAM;import static org.apache.solr.common.params.CollectionAdminParams.CREATE_NODE_SET_SHUFFLE_PARAM;-import static org.apache.solr.common.params.CollectionAdminParams.NRT_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.PROPERTY_PREFIX;-import static org.apache.solr.common.params.CollectionAdminParams.PULL_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.REPLICATION_FACTOR;-import static org.apache.solr.common.params.CollectionAdminParams.TLOG_REPLICAS;import static org.apache.solr.common.params.CommonAdminParams.ASYNC;import static org.apache.solr.common.params.CommonParams.NAME;import static org.apache.solr.common.params.CoreAdminParams.BACKUP_ID;@@ -41,6 +38,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;import java.util.HashMap;import java.util.Map;import java.util.Set;+import java.util.stream.Collectors;+import java.util.stream.Stream;import javax.inject.Inject;import javax.ws.rs.POST;import javax.ws.rs.Path;@@ -51,6 +50,7 @@ import org.apache.solr.client.api.model.SolrJerseyResponse;import org.apache.solr.client.api.model.SubResponseAccumulatingJerseyResponse;import org.apache.solr.client.solrj.SolrResponse;import org.apache.solr.client.solrj.util.SolrIdentifierValidator;+import org.apache.solr.cloud.api.collections.CollectionHandlingUtils;import org.apache.solr.common.SolrException;import org.apache.solr.common.cloud.ZkNodeProps;import org.apache.solr.common.params.CollectionParams;@@ -71,14 +71,14 @@ import org.apache.solr.response.SolrQueryResponse;public class RestoreCollectionAPI extends BackupAPIBase {private static final Set<String> CREATE_PARAM_ALLOWLIST =- Set.of(- COLL_CONF,- REPLICATION_FACTOR,- NRT_REPLICAS,- TLOG_REPLICAS,- PULL_REPLICAS,- CREATE_NODE_SET_PARAM,- CREATE_NODE_SET_SHUFFLE_PARAM);+ Stream.concat(+ CollectionHandlingUtils.numReplicasProperties().stream(),+ Stream.of(+ COLL_CONF,+ REPLICATION_FACTOR,+ CREATE_NODE_SET_PARAM,+ CREATE_NODE_SET_SHUFFLE_PARAM))+ .collect(Collectors.toUnmodifiableSet());@Injectpublic RestoreCollectionAPI(diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.javaindex 14113386b04..ad0999fc6cf 100644--- a/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/cluster/placement/plugins/AffinityPlacementFactoryTest.java@@ -135,7 +135,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -180,7 +180,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(2, 2, 2));+ ReplicaCount.of(2, 2, 2));PlacementPlan pp =plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());@@ -207,7 +207,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(7, 0, 0));+ ReplicaCount.of(7, 0, 0));pp = plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());assertEquals(21, pp.getReplicaPlacements().size()); // 3 shards, 7 replicas eachplacements = new HashSet<>();@@ -230,7 +230,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(8, 0, 0));+ ReplicaCount.of(8, 0, 0));plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());fail("Placing 8 replicas should not be possible given only 7 nodes have enough space");} catch (PlacementException e) {@@ -276,7 +276,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(1, 1, 0));+ ReplicaCount.of(1, 1, 0));// The replicas must be placed on the most appropriate nodes, i.e. those that do not already// have a replica for the shard and then on the node with the lowest number of cores. NRT are@@ -388,7 +388,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(2, 1, 0));+ ReplicaCount.of(2, 1, 0));PlacementPlan pp =plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());// Shard 1: The NRT's should go to the med cores node on AZ2 and low core on az3 (even though a@@ -414,7 +414,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(0, 0, 2));+ ReplicaCount.of(0, 0, 2));pp = plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());// Shard 1: Given node AZ3_TLOGPULL is taken by the TLOG replica, the PULL should go to// AZ1_TLOGPULL_LOWFREEDISK and AZ2_TLOGPULL@@ -479,7 +479,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(countNrtToPlace, 0, 0));+ ReplicaCount.of(countNrtToPlace, 0, 0));PlacementPlan pp =plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());verifyPlacements(@@ -524,7 +524,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(0, 0, 1));+ ReplicaCount.of(0, 0, 1));PlacementPlan pp =plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());@@ -543,7 +543,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(it.next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(0, 0, 1));+ ReplicaCount.of(0, 0, 1));pp = plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());expectedPlacements = Set.of("2 PULL 0");verifyPlacements(expectedPlacements, pp, collectionBuilder.getShardBuilders(), liveNodes);@@ -582,7 +582,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {.map(Shard::getShardName).collect(Collectors.toSet()),cluster.getLiveNodes(),- new ReplicaCount(2, 2, 2));+ ReplicaCount.of(2, 2, 2));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);// 2 shards, 6 replicas@@ -654,7 +654,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {.map(Shard::getShardName).collect(Collectors.toSet()),cluster.getLiveNodes(),- new ReplicaCount(2, 2, 2));+ ReplicaCount.of(2, 2, 2));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);// 2 shards, 6 replicas@@ -733,7 +733,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {.map(Shard::getShardName).collect(Collectors.toSet()),cluster.getLiveNodes(),- new ReplicaCount(1, 0, 1));+ ReplicaCount.of(1, 0, 1));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);assertEquals(4, pp.getReplicaPlacements().size());@@ -782,7 +782,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {.map(Set::of).orElseGet(Collections::emptySet),cluster.getLiveNodes(),- new ReplicaCount(0, 1, 1));+ ReplicaCount.of(0, 1, 1));assertThrows(PlacementException.class,@@ -797,7 +797,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {.map(Shard::getShardName).collect(Collectors.toSet()),cluster.getLiveNodes(),- new ReplicaCount(0, 1, 1));+ ReplicaCount.of(0, 1, 1));assertThrows(PlacementException.class,@@ -854,7 +854,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {primaryCollection,Set.of("shard1", "shard2"),cluster.getLiveNodes(),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);assertEquals(2, pp.getReplicaPlacements().size());@@ -868,7 +868,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {placementRequest =new PlacementRequestImpl(- primaryCollection, Set.of("shard1"), cluster.getLiveNodes(), new ReplicaCount(3, 0, 0));+ primaryCollection, Set.of("shard1"), cluster.getLiveNodes(), ReplicaCount.of(3, 0, 0));try {pp = plugin.computePlacement(placementRequest, placementContext);fail("should generate 'Not enough eligible nodes' failure here");@@ -918,7 +918,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {primaryCollection,shuffle(Arrays.asList("shard2", "shard1")),shuffle(cluster.getLiveNodes()),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);assertEquals(2, pp.getReplicaPlacements().size());@@ -946,7 +946,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {placementRequest =new PlacementRequestImpl(- primaryCollection, Set.of("shard3"), cluster.getLiveNodes(), new ReplicaCount(1, 0, 0));+ primaryCollection, Set.of("shard3"), cluster.getLiveNodes(), ReplicaCount.of(1, 0, 0));try {pp = plugin.computePlacement(placementRequest, placementContext);fail("should generate 'has no replicas on eligible nodes' failure here");@@ -1181,7 +1181,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {collection,Set.of("shard1"),placementContext.getCluster().getLiveNodes(),- new ReplicaCount(3, 0, 0));+ ReplicaCount.of(3, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);assertEquals("expected 3 placements: " + pp, 3, pp.getReplicaPlacements().size());@@ -1209,7 +1209,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {collection,Set.of("shard1"),placementContext.getCluster().getLiveNodes(),- new ReplicaCount(6, 0, 0));+ ReplicaCount.of(6, 0, 0));pp = plugin.computePlacement(placementRequest, placementContext);assertEquals("expected 6 placements: " + pp, 6, pp.getReplicaPlacements().size());@@ -1236,7 +1236,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {collection,Set.of("shard1"),placementContext.getCluster().getLiveNodes(),- new ReplicaCount(6, 0, 0));+ ReplicaCount.of(6, 0, 0));pp = plugin.computePlacement(placementRequest, placementContext);assertEquals("expected 6 placements: " + pp, 6, pp.getReplicaPlacements().size());nodeNamesByType.clear();@@ -1353,7 +1353,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(nrtReplicas, tlogReplicas, pullReplicas));+ ReplicaCount.of(nrtReplicas, tlogReplicas, pullReplicas));long start = System.nanoTime();PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -1444,7 +1444,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -1459,7 +1459,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(2, 0, 0));+ ReplicaCount.of(2, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -1529,7 +1529,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -1544,7 +1544,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(2, 0, 0));+ ReplicaCount.of(2, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -1588,7 +1588,7 @@ public class AffinityPlacementFactoryTest extends AbstractPlacementFactoryTest {solrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/plugins/MinimizeCoresPlacementFactoryTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/plugins/MinimizeCoresPlacementFactoryTest.javaindex 03a272110ac..d85d30c8a13 100644--- a/solr/core/src/test/org/apache/solr/cluster/placement/plugins/MinimizeCoresPlacementFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/cluster/placement/plugins/MinimizeCoresPlacementFactoryTest.java@@ -102,7 +102,7 @@ public class MinimizeCoresPlacementFactoryTest extends AbstractPlacementFactoryTsolrCollection,Set.of(solrCollection.shards().iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(1, 0, 0));+ ReplicaCount.of(1, 0, 0));PlacementPlan pp = plugin.computePlacement(placementRequest, placementContext);@@ -149,7 +149,7 @@ public class MinimizeCoresPlacementFactoryTest extends AbstractPlacementFactoryTsolrCollection,solrCollection.getShardNames(),new HashSet<>(liveNodes),- new ReplicaCount(1, 1, 0));+ ReplicaCount.of(1, 1, 0));// The replicas must be placed on the most appropriate nodes, i.e. those that do not already// have a replica for the shard and then on the node with the lowest number of cores. NRT are@@ -200,7 +200,7 @@ public class MinimizeCoresPlacementFactoryTest extends AbstractPlacementFactoryTsolrCollection,Set.of(solrCollection.iterator().next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(0, 0, 1));+ ReplicaCount.of(0, 0, 1));PlacementPlan pp =plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());@@ -219,7 +219,7 @@ public class MinimizeCoresPlacementFactoryTest extends AbstractPlacementFactoryTsolrCollection,Set.of(it.next().getShardName()),new HashSet<>(liveNodes),- new ReplicaCount(0, 0, 1));+ ReplicaCount.of(0, 0, 1));pp = plugin.computePlacement(placementRequest, clusterBuilder.buildPlacementContext());expectedPlacements = Set.of("2 PULL 0");verifyPlacements(expectedPlacements, pp, collectionBuilder.getShardBuilders(), liveNodes);diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.javaindex d1802d2855e..a89b3f8dd60 100644--- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java+++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java@@ -150,7 +150,7 @@ public class ZkStateReader implements SolrCloseable {private static final String SOLR_ENVIRONMENT = "environment";- public static final String REPLICA_TYPE = "type";+ public static final String REPLICA_TYPE = CollectionAdminParams.REPLICA_TYPE;public static final String CONTAINER_PLUGINS = "plugin";diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.javaindex 5f77eae75ee..54a03cd7031 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java@@ -128,21 +128,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>return SolrRequestType.ADMIN.toString();}- private static void writeNumReplicas(ReplicaCount numReplicas, ModifiableSolrParams params) {- if (numReplicas.contains(Replica.Type.NRT)) {- params.add(- CollectionAdminParams.NRT_REPLICAS, String.valueOf(numReplicas.get(Replica.Type.NRT)));- }- if (numReplicas.contains(Replica.Type.TLOG)) {- params.add(- CollectionAdminParams.TLOG_REPLICAS, String.valueOf(numReplicas.get(Replica.Type.TLOG)));- }- if (numReplicas.contains(Replica.Type.PULL)) {- params.add(- CollectionAdminParams.PULL_REPLICAS, String.valueOf(numReplicas.get(Replica.Type.PULL)));- }- }-/*** Take the request specific basic auth creds on this admin request and propagate them to a* related request if does not already have credentials set, such as a@@ -461,7 +446,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>ImplicitDocRouter.NAME,null,checkNotNull("shards", shards),- new ReplicaCount(numNrtReplicas, numTlogReplicas, numPullReplicas));+ ReplicaCount.of(numNrtReplicas, numTlogReplicas, numPullReplicas));}/**@@ -505,7 +490,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>null,numShards,null,- new ReplicaCount(numNrtReplicas, numTlogReplicas, numPullReplicas));+ ReplicaCount.of(numNrtReplicas, numTlogReplicas, numPullReplicas));}/**@@ -698,7 +683,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>if (properties != null) {addProperties(params, properties);}- writeNumReplicas(numReplicas, params);+ numReplicas.writeProps(params);if (Boolean.TRUE.equals(perReplicaState)) {params.set(CollectionAdminParams.PER_REPLICA_STATE, perReplicaState);}@@ -1390,7 +1375,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>if (replicationFactor != null) {params.set(CollectionAdminParams.REPLICATION_FACTOR, replicationFactor);}- writeNumReplicas(numReplicas, params);+ numReplicas.writeProps(params);if (properties != null) {addProperties(params, properties);}@@ -2426,8 +2411,6 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>// ADDREPLICA requestpublic static class AddReplica extends AsyncCollectionAdminRequest {- private static final String REPLICA_TYPE_PARAM = "type";-protected String collection;protected String shard;protected String node;@@ -2597,12 +2580,12 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>params.add(CoreAdminParams.NAME, coreName);}if (type != null) {- params.add(REPLICA_TYPE_PARAM, type.name());+ params.add(CollectionAdminParams.REPLICA_TYPE, type.name());}if (properties != null) {addProperties(params, properties);}- writeNumReplicas(numReplicas, params);+ numReplicas.writeProps(params);if (createNodeSet != null) {params.add(CREATE_NODE_SET_PARAM, createNodeSet);}diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.javaindex f49087967e3..dc59a5698d3 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java@@ -113,11 +113,7 @@ public class DocCollection extends ZkNodeProps implements Iterable<Slice> {this.nodeNameLeaderReplicas = new HashMap<>();this.nodeNameReplicas = new HashMap<>();this.replicationFactor = (Integer) verifyProp(props, CollectionStateProps.REPLICATION_FACTOR);- this.numReplicas =- new ReplicaCount(- (Integer) verifyProp(props, CollectionStateProps.NRT_REPLICAS, 0),- (Integer) verifyProp(props, CollectionStateProps.TLOG_REPLICAS, 0),- (Integer) verifyProp(props, CollectionStateProps.PULL_REPLICAS, 0));+ this.numReplicas = ReplicaCount.fromProps(props);this.perReplicaState =(Boolean) verifyProp(props, CollectionStateProps.PER_REPLICA_STATE, Boolean.FALSE);if (this.perReplicaState) {@@ -262,18 +258,24 @@ public class DocCollection extends ZkNodeProps implements Iterable<Slice> {public static Object verifyProp(Map<String, Object> props, String propName, Object def) {Object o = props.get(propName);- if (o == null) return def;+ if (o == null) {+ return def;+ }switch (propName) {case CollectionStateProps.REPLICATION_FACTOR:- case CollectionStateProps.NRT_REPLICAS:- case CollectionStateProps.PULL_REPLICAS:- case CollectionStateProps.TLOG_REPLICAS:return Integer.parseInt(o.toString());case CollectionStateProps.PER_REPLICA_STATE:case CollectionStateProps.READ_ONLY:return Boolean.parseBoolean(o.toString());case "snitch":+ return o;default:+ // Properties associated with a number of replicas are parsed as integers.+ for (Replica.Type replicaType : Replica.Type.values()) {+ if (replicaType.numReplicasPropertyName.equals(propName)) {+ return Integer.parseInt(o.toString());+ }+ }return o;}}@@ -559,9 +561,6 @@ public class DocCollection extends ZkNodeProps implements Iterable<Slice> {/** JSON properties related to a collection's state. */public interface CollectionStateProps {- String NRT_REPLICAS = "nrtReplicas";- String PULL_REPLICAS = "pullReplicas";- String TLOG_REPLICAS = "tlogReplicas";String REPLICATION_FACTOR = "replicationFactor";String READ_ONLY = "readOnly";String CONFIGNAME = "configName";diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java b/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.javaindex 854b20fa815..abeef4a9fc6 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java@@ -26,6 +26,7 @@ import java.util.Objects;import java.util.Set;import java.util.concurrent.atomic.AtomicReference;import org.apache.solr.common.MapWriter;+import org.apache.solr.common.params.CollectionAdminParams;import org.apache.solr.common.util.StrUtils;import org.apache.solr.common.util.Utils;import org.slf4j.Logger;@@ -103,31 +104,41 @@ public class Replica extends ZkNodeProps implements MapWriter {* support NRT (soft commits) and RTG. Any {@link Type#NRT} replica can become a leader. A shard* leader will forward updates to all active {@link Type#NRT} and {@link Type#TLOG} replicas.*/- NRT(true),+ NRT(true, CollectionAdminParams.NRT_REPLICAS),/*** Writes to transaction log, but not to index, uses replication. Any {@link Type#TLOG} replica* can become leader (by first applying all local transaction log elements). If a replica is of* type {@link Type#TLOG} but is also the leader, it will behave as a {@link Type#NRT}. A shard* leader will forward updates to all active {@link Type#NRT} and {@link Type#TLOG} replicas.*/- TLOG(true),+ TLOG(true, CollectionAdminParams.TLOG_REPLICAS),/*** Doesn’t index or writes to transaction log. Just replicates from {@link Type#NRT} or {@link* Type#TLOG} replicas. {@link Type#PULL} replicas can’t become shard leaders (i.e., if there* are only pull replicas in the collection at some point, updates will fail same as if there is* no leaders, queries continue to work), so they don’t even participate in elections.*/- PULL(false);+ PULL(false, CollectionAdminParams.PULL_REPLICAS);public final boolean leaderEligible;+ public final String numReplicasPropertyName;- Type(boolean b) {- this.leaderEligible = b;+ Type(boolean leaderEligible, String numReplicasPropertyName) {+ this.leaderEligible = leaderEligible;+ this.numReplicasPropertyName = numReplicasPropertyName;}public static Type get(String name) {return StrUtils.isNullOrEmpty(name) ? NRT : Type.valueOf(name.toUpperCase(Locale.ROOT));}++ /**+ * Returns a default replica type. It is most notably used by the replica factor, which maps+ * onto this replica type. This replica type needs to be leader-eligible.+ */+ public static Type defaultType() {+ return NRT;+ }}// immutablediff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ReplicaCount.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ReplicaCount.javaindex 35c35c3ba76..a76f09d163d 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ReplicaCount.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ReplicaCount.java@@ -19,30 +19,120 @@ package org.apache.solr.common.cloud;import java.util.Arrays;import java.util.EnumMap;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;+import org.apache.solr.common.params.ModifiableSolrParams;/** 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);+ }++ /**+ * Creates a {@link ReplicaCount} from a message.+ *+ * <p>This method has a rich logic for defaulting parameters. A collection can optionally be+ * provided as a fallback for all properties. Among all properties, replica factor is applied as+ * the number of replicas for the default replica type. The default replica type can be provided+ * as a property, or else comes from {@link Replica.Type#defaultType()}.+ *+ * <p>Not all capabilities apply on every call of this method. For example, the message may not+ * contain any replication factor.+ *+ * @param message a message.+ * @param collection an optional collection providing defaults.+ * @param defaultReplicationFactor an additional optional default replica factor, if none is found+ * in the collection.+ */+ public static ReplicaCount fromMessage(+ ZkNodeProps message, DocCollection collection, Integer defaultReplicationFactor) {+ // Default replica type can be overridden by a property.+ Replica.Type defaultReplicaType =+ Replica.Type.valueOf(+ message+ .getStr(CollectionAdminParams.REPLICA_TYPE, Replica.Type.defaultType().name())+ .toUpperCase(Locale.ROOT));+ ReplicaCount replicaCount = new ReplicaCount();+ for (Replica.Type replicaType : Replica.Type.values()) {+ final Integer count;+ if (replicaType == defaultReplicaType) {+ // Number of replicas for the default replica type defaults to the replication factor.+ // Replication factor can be overridden by a property, or a custom default.+ Integer defaultCount =+ (null != collection)+ ? collection.getInt(+ replicaType.numReplicasPropertyName,+ collection.getInt(+ CollectionAdminParams.REPLICATION_FACTOR, defaultReplicationFactor))+ : defaultReplicationFactor;+ count =+ message.getInt(+ replicaType.numReplicasPropertyName,+ message.getInt(CollectionAdminParams.REPLICATION_FACTOR, defaultCount));+ } else {+ Integer defaultCount =+ (null != collection)+ ? collection.getInt(replicaType.numReplicasPropertyName, null)+ : null;+ count = message.getInt(replicaType.numReplicasPropertyName, defaultCount);+ }+ replicaCount.put(replicaType, count);+ }+ return replicaCount;+ }++ /**+ * Creates a {@link ReplicaCount} from a properties map.+ *+ * <p>This method is much simpler than {@link #fromMessage}, as it only considers properties+ * containing a number of replicas (and ignores other properties such as the replication factor).+ *+ * @param propMap a properties map+ */+ public static ReplicaCount fromProps(Map<String, Object> propMap) {+ ReplicaCount replicaCount = new ReplicaCount();+ for (Replica.Type replicaType : Replica.Type.values()) {+ Object value = propMap.get(replicaType.numReplicasPropertyName);+ if (null != value) {+ replicaCount.put(replicaType, Integer.parseInt(value.toString()));+ }+ }+ return replicaCount;+ }+/*** Returns the number of replicas for a given type.*@@ -61,6 +151,33 @@ public final class ReplicaCount {return countByType.containsKey(type);}+ /** Returns the replica types for which a number of replicas was explicitely defined. */+ public Set<Replica.Type> keySet() {+ return countByType.keySet();+ }++ /**+ * Add properties for replica counts as integers to a properties map.+ *+ * @param propMap a properties map.+ */+ public void writeProps(Map<String, Object> propMap) {+ for (Map.Entry<Replica.Type, Integer> entry : countByType.entrySet()) {+ propMap.put(entry.getKey().numReplicasPropertyName, entry.getValue());+ }+ }++ /**+ * Add properties for replica counts as integers to Solr parameters.+ *+ * @param params a set of modifiable Solr parameters.+ */+ public void writeProps(ModifiableSolrParams params) {+ for (Map.Entry<Replica.Type, Integer> entry : countByType.entrySet()) {+ params.set(entry.getKey().numReplicasPropertyName, entry.getValue());+ }+ }+/*** Defines the number of replicas for a given type.*@@ -100,6 +217,12 @@ public final class ReplicaCount {return countByType.values().stream().reduce(Integer::sum).orElse(0);}+ /** Returns whether there is at least one replica which can be a leader. */+ public boolean hasLeaderReplica() {+ return countByType.entrySet().stream()+ .anyMatch(e -> e.getKey().leaderEligible && e.getValue() > 0);+ }+/*** Returns the first non-zero replica type that can be a leader.*@@ -118,9 +241,17 @@ public final class ReplicaCount {+ "), there must be at least one leader-eligible replica");}- /** Validate that there is at least one replica that can be a leader. */- public void validate() {- getLeaderType();+ @Override+ public boolean equals(Object o) {+ if (this == o) return true;+ if (o == null || getClass() != o.getClass()) return false;+ ReplicaCount that = (ReplicaCount) o;+ return Objects.equals(countByType, that.countByType);+ }++ @Override+ public int hashCode() {+ return Objects.hash(countByType);}/** Returns a representation of this class which can be used for debugging. */diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.javaindex 33e5d1cf843..a7c6043fb19 100644--- a/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java+++ b/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java@@ -49,6 +49,8 @@ public interface CollectionAdminParams {String REPLICATION_FACTOR = "replicationFactor";+ String REPLICA_TYPE = "type";+/*** A parameter which specifies if the provided list of Solr nodes (via {@linkplain* #CREATE_NODE_SET_PARAM}) should be shuffled before being used.diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/ReplicaCountTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/ReplicaCountTest.javaindex 44c371debad..76cbe38bf30 100644--- a/solr/solrj/src/test/org/apache/solr/common/cloud/ReplicaCountTest.java+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/ReplicaCountTest.java@@ -18,10 +18,10 @@ package org.apache.solr.common.cloud;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertFalse;-import static org.junit.Assert.assertThrows;import static org.junit.Assert.assertTrue;-import org.apache.solr.common.SolrException;+import java.util.Map;+import java.util.Set;import org.junit.Test;/** Unit tests for {@link ReplicaCount}. */@@ -116,19 +116,6 @@ public class ReplicaCountTest {assertEquals("nrt=1, tlog=2, pull=0", replicaCount.toString());}- @Test- public void testValidate() {- ReplicaCount replicaCountNrtOnly = ReplicaCount.of(Replica.Type.NRT, 1);- replicaCountNrtOnly.validate(); // Should not throw-- ReplicaCount replicaCountPullOnly = ReplicaCount.of(Replica.Type.PULL, 1);- Throwable t = assertThrows(SolrException.class, replicaCountPullOnly::validate);- assertEquals(- "Unexpected number of replicas (nrt=0, tlog=0, pull=1), there must "- + "be at least one leader-eligible replica",- t.getMessage());- }-@Testpublic void testGetLeaderType() {// With only 1 NRT, NRT should be returned.@@ -144,4 +131,89 @@ public class ReplicaCountTest {replicaCount.decrement(Replica.Type.NRT);assertEquals(Replica.Type.TLOG, replicaCount.getLeaderType());}++ @Test+ public void testHasLeaderReplica() {+ assertTrue(ReplicaCount.of(Replica.Type.NRT, 1).hasLeaderReplica());+ assertTrue(ReplicaCount.of(Replica.Type.TLOG, 1).hasLeaderReplica());+ assertFalse(ReplicaCount.of(Replica.Type.PULL, 1).hasLeaderReplica());+ }++ @Test+ public void createFromProps() {+ ReplicaCount numReplicas =+ ReplicaCount.fromProps(+ Map.of("nrtReplicas", "1", "tlogReplicas", "2", "pullReplicas", "3"));+ assertEquals(ReplicaCount.of(1, 2, 3), numReplicas);++ numReplicas =+ ReplicaCount.fromProps(Map.of("nrtReplicas", 1, "tlogReplicas", 2, "pullReplicas", 3));+ assertEquals(ReplicaCount.of(1, 2, 3), numReplicas);++ numReplicas = ReplicaCount.fromProps(Map.of("tlogReplicas", 1));+ assertEquals(Set.of(Replica.Type.TLOG), numReplicas.keySet());+ }++ @Test+ public void createFromMessage() {+ ReplicaCount numReplicas =+ ReplicaCount.fromMessage(+ new ZkNodeProps(Map.of("nrtReplicas", "1", "tlogReplicas", "2", "pullReplicas", "3")));+ assertEquals(ReplicaCount.of(1, 2, 3), numReplicas);++ numReplicas =+ ReplicaCount.fromMessage(+ new ZkNodeProps(Map.of("nrtReplicas", 1, "tlogReplicas", 2, "pullReplicas", 3)));+ assertEquals(ReplicaCount.of(1, 2, 3), numReplicas);++ numReplicas = ReplicaCount.fromMessage(new ZkNodeProps(Map.of("tlogReplicas", 1)));+ assertEquals(Set.of(Replica.Type.TLOG), numReplicas.keySet());+ }++ @Test+ public void createFromMessageWithReplicationFactor() {+ // "replicationFactor" in message+ ReplicaCount numReplicas =+ ReplicaCount.fromMessage(+ new ZkNodeProps(Map.of("replicationFactor", 10, "tlogReplicas", 2, "pullReplicas", 3)));+ assertEquals(ReplicaCount.of(10, 2, 3), numReplicas);++ // "replicationFactor" and "type" in message+ numReplicas =+ ReplicaCount.fromMessage(+ new ZkNodeProps(+ Map.of(+ "type", "tlog", "replicationFactor", 10, "nrtReplicas", 1, "pullReplicas", 3)));+ assertEquals(ReplicaCount.of(1, 10, 3), numReplicas);+ }++ @Test+ public void createFromMessageWithDefaultReplicationFactor() {+ // default replication factor specified+ ReplicaCount numReplicas =+ ReplicaCount.fromMessage(+ new ZkNodeProps(Map.of("tlogReplicas", 2, "pullReplicas", 3)), null, 10);+ assertEquals(ReplicaCount.of(10, 2, 3), numReplicas);++ // default replication factor specified and "type" in message+ numReplicas =+ ReplicaCount.fromMessage(+ new ZkNodeProps(Map.of("type", "tlog", "nrtReplicas", 1, "pullReplicas", 3)), null, 10);+ assertEquals(ReplicaCount.of(1, 10, 3), numReplicas);+ }++ @Test+ public void createFromMessageWithCollection() {+ DocCollection collection =+ DocCollection.create(+ "coll",+ Map.of(),+ Map.of("nrtReplicas", 1, "tlogReplicas", 2, "pullReplicas", 3),+ null,+ 1,+ null);+ ReplicaCount numReplicas =+ ReplicaCount.fromMessage(new ZkNodeProps(Map.of("tlogReplicas", 1)), collection);+ assertEquals(ReplicaCount.of(1, 1, 3), numReplicas);+ }}