Apache Solr open-source search software
SOLR-4118: Fix replicationFactor to align with industry usage
Yonik Seeley6f6211d310ea
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 96a4b1b590b..def50826415 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -114,6 +114,15 @@ New Features* SOLR-3531: Allowing configuring maxMergeSizeMB and maxCachedMB whenusing NRTCachingDirectoryFactory. (Andy Laird via Mark Miller)+* SOLR-4118: Fix replicationFactor to align with industry usage.+ replicationFactor now means the total number of copies+ of a document stored in the collection (or the total number of+ physical indexes for a single logical slice of the collection).+ For example if replicationFactor=3 then for a given shard there+ will be a total of 3 replicas (one of which will normally be+ designated as the leader.) (yonik)++Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.javaindex 7ffb431f8b4..9887549c038 100644--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java@@ -174,11 +174,11 @@ public class OverseerCollectionProcessor implements Runnable {// look at the replication factor and see if it matches reality// if it does not, find best nodes to create more cores- int numReplica = msgStrToInt(message, REPLICATION_FACTOR, 0);+ int repFactor = msgStrToInt(message, REPLICATION_FACTOR, 1);int numSlices = msgStrToInt(message, NUM_SLICES, 0);int maxShardsPerNode = msgStrToInt(message, MAX_SHARDS_PER_NODE, 1);- if (numReplica < 0) {+ if (repFactor <= 0) {SolrException.log(log, REPLICATION_FACTOR + " must be > 0");return false;}@@ -208,12 +208,11 @@ public class OverseerCollectionProcessor implements Runnable {return false;}- int numShardsPerSlice = numReplica + 1;- if (numShardsPerSlice > nodeList.size()) {+ if (repFactor > nodeList.size()) {log.warn("Specified "+ REPLICATION_FACTOR+ " of "- + numReplica+ + repFactor+ " on collection "+ collectionName+ " is higher than or equal to the number of Solr instances currently live ("@@ -222,21 +221,21 @@ public class OverseerCollectionProcessor implements Runnable {}int maxShardsAllowedToCreate = maxShardsPerNode * nodeList.size();- int requestedShardsToCreate = numSlices * numShardsPerSlice;+ int requestedShardsToCreate = numSlices * repFactor;if (maxShardsAllowedToCreate < requestedShardsToCreate) {log.error("Cannot create collection " + collectionName + ". Value of "+ MAX_SHARDS_PER_NODE + " is " + maxShardsPerNode+ ", and the number of live nodes is " + nodeList.size()+ ". This allows a maximum of " + maxShardsAllowedToCreate+ " to be created. Value of " + NUM_SLICES + " is " + numSlices- + " and value of " + REPLICATION_FACTOR + " is " + numReplica+ + " and value of " + REPLICATION_FACTOR + " is " + repFactor+ ". This requires " + requestedShardsToCreate+ " shards to be created (higher than the allowed number)");return false;}for (int i = 1; i <= numSlices; i++) {- for (int j = 1; j <= numShardsPerSlice; j++) {+ for (int j = 1; j <= repFactor; j++) {String nodeName = nodeList.get(((i - 1) + (j - 1)) % nodeList.size());String sliceName = "shard" + i;String shardName = collectionName + "_" + sliceName + "_replica" + j;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 6b5e7ea0e59..83e28a7f33e 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@@ -176,7 +176,7 @@ public class CollectionsHandler extends RequestHandlerBase {private void handleCreateAction(SolrQueryRequest req,SolrQueryResponse rsp) throws InterruptedException, KeeperException {log.info("Creating Collection : " + req.getParamString());- Integer numReplicas = req.getParams().getInt(OverseerCollectionProcessor.REPLICATION_FACTOR, 0);+ Integer numReplicas = req.getParams().getInt(OverseerCollectionProcessor.REPLICATION_FACTOR, 1);String name = req.getParams().required().get("name");String configName = req.getParams().get("collection.configName");String numShards = req.getParams().get(OverseerCollectionProcessor.NUM_SLICES);diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.javaindex bd6543cd02a..20df6262734 100644--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java@@ -739,9 +739,9 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {for (int i = 0; i < cnt; i++) {int numShards = _TestUtil.nextInt(random(), 0, shardCount) + 1;- int numReplica = _TestUtil.nextInt(random(), 0, 3) + 1;- int maxShardsPerNode = (((numShards * (numReplica + 1)) / getCommonCloudSolrServer().getZkStateReader().getClusterState().getLiveNodes().size())) + 1;- createCollection(collectionInfos, i, numShards, numReplica, maxShardsPerNode);+ int replicationFactor = _TestUtil.nextInt(random(), 0, 3) + 2;+ int maxShardsPerNode = (((numShards * replicationFactor) / getCommonCloudSolrServer().getZkStateReader().getClusterState().getLiveNodes().size())) + 1;+ createCollection(collectionInfos, i, numShards, replicationFactor, maxShardsPerNode);}Set<Entry<String,List<Integer>>> collectionInfosEntrySet = collectionInfos.entrySet();@@ -844,7 +844,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {params.set("action", CollectionAction.CREATE.toString());params.set("numShards", 1);- params.set(OverseerCollectionProcessor.REPLICATION_FACTOR, 1);+ params.set(OverseerCollectionProcessor.REPLICATION_FACTOR, 2);collectionName = "acollectionafterbaddelete";params.set("name", collectionName);@@ -854,7 +854,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {List<Integer> list = new ArrayList<Integer> (2);list.add(1);- list.add(1);+ list.add(2);checkForCollection(collectionName, list);url = getUrlFromZk(collectionName);@@ -871,10 +871,10 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {// test maxShardsPerNodeint liveNodes = getCommonCloudSolrServer().getZkStateReader().getClusterState().getLiveNodes().size();int numShards = (liveNodes/2) + 1;- int numReplica = 1;+ int replicationFactor = 2;int maxShardsPerNode = 1;collectionInfos = new HashMap<String,List<Integer>>();- createCollection(collectionInfos, cnt, numShards, numReplica, maxShardsPerNode);+ createCollection(collectionInfos, cnt, numShards, replicationFactor, maxShardsPerNode);// TODO: enable this check after removing the 60 second wait in it//checkCollectionIsNotCreated(collectionInfos.keySet().iterator().next());@@ -1030,7 +1030,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {int expectedSlices = numShardsNumReplicaList.get(0);// The Math.min thing is here, because we expect replication-factor to be reduced to if there are not enough live nodes to spread all shards of a collection over different nodes- int expectedShardsPerSlice = numShardsNumReplicaList.get(1) + 1;+ int expectedShardsPerSlice = numShardsNumReplicaList.get(1);int expectedTotalShards = expectedSlices * expectedShardsPerSlice;Map<String,DocCollection> collections = clusterStatediff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java b/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.javaindex 60b13652ad4..3272b654e90 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java@@ -35,7 +35,7 @@ public class Slice extends ZkNodeProps {private final String name;private final DocRouter.Range range;- private final Integer replicationFactor;+ private final Integer replicationFactor; // FUTURE: optional per-slice override of the collection replicationFactorprivate final Map<String,Replica> replicas;private final Replica leader;diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.javaindex 151a8fde4a7..3d26191d09b 100644--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java@@ -69,7 +69,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {r = new Random(random().nextLong());}- protected int shardCount = 4;+ protected int shardCount = 4; // the actual number of solr cores that will be created in the cluster/*** Sub classes can set this flag in their constructor to true if they