Skip to content

Apache Lucene open-source search software

SOLR-11560: Specifying the replicationFactor parameter while restoring a collection would lead to extra tlog and pull replicas being created

Varun Thacker07652a528957
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c1b8f9847f7..16a6150c63e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -95,6 +95,9 @@ Bug Fixes
* SOLR-9440: The ZkStateReader.removeCollectionStateWatcher method can cache a DocCollection reference and
never update it causing stale state to be returned in ClusterState. (shalin)
+* SOLR-11560: Specifying the replicationFactor parameter while restoring a collection would lead to extra tlog
+ and pull replicas being created (Peter Szantai-Kis, Varun Thacker)
+
Optimizations
----------------------
* SOLR-11285: Refactor autoscaling framework to avoid direct references to Zookeeper and Solr
diff --git a/solr/core/src/java/org/apache/solr/cloud/RestoreCmd.java b/solr/core/src/java/org/apache/solr/cloud/RestoreCmd.java
index f25a3cf7786..900ca6413a1 100644
--- a/solr/core/src/java/org/apache/solr/cloud/RestoreCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/RestoreCmd.java
@@ -350,8 +350,8 @@ public class RestoreCmd implements OverseerCollectionMessageHandler.Cmd {
}
}
- private int getInt(ZkNodeProps message, String propertyName, Integer default1, int default2) {
- Integer value = message.getInt(REPLICATION_FACTOR, default1);
- return value!=null?value:default2;
+ private int getInt(ZkNodeProps message, String propertyName, Integer count, int defaultValue) {
+ Integer value = message.getInt(propertyName, count);
+ return value!=null ? value:defaultValue;
}
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/AbstractCloudBackupRestoreTestCase.java b/solr/core/src/test/org/apache/solr/cloud/AbstractCloudBackupRestoreTestCase.java
index 526a8dfab65..93c9c161cd5 100644
--- a/solr/core/src/test/org/apache/solr/cloud/AbstractCloudBackupRestoreTestCase.java
+++ b/solr/core/src/test/org/apache/solr/cloud/AbstractCloudBackupRestoreTestCase.java
@@ -57,6 +57,10 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
protected static final int NUM_SHARDS = 2;//granted we sometimes shard split to get more
+ int replFactor;
+ int numTlogReplicas;
+ int numPullReplicas;
+
private static long docsSeed; // see indexDocs()
@BeforeClass
@@ -84,9 +88,9 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
public void test() throws Exception {
boolean isImplicit = random().nextBoolean();
boolean doSplitShardOperation = !isImplicit && random().nextBoolean();
- int replFactor = TestUtil.nextInt(random(), 1, 2);
- int numTlogReplicas = TestUtil.nextInt(random(), 0, 1);
- int numPullReplicas = TestUtil.nextInt(random(), 0, 1);
+ replFactor = TestUtil.nextInt(random(), 1, 2);
+ numTlogReplicas = TestUtil.nextInt(random(), 0, 1);
+ numPullReplicas = TestUtil.nextInt(random(), 0, 1);
CollectionAdminRequest.Create create = isImplicit ?
// NOTE: use shard list with same # of shards as NUM_SHARDS; we assume this later
@@ -241,6 +245,12 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
CollectionAdminRequest.Restore restore = CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
.setLocation(backupLocation).setRepositoryName(getBackupRepoName());
+
+ //explicitly specify the replicationFactor/pullReplicas/nrtReplicas/tlogReplicas .
+ //Value is still the same as the original. maybe test with different values that the original for better test coverage
+ if (random().nextBoolean()) {
+ restore.setReplicationFactor(replFactor);
+ }
if (backupCollection.getReplicas().size() > cluster.getJettySolrRunners().size()) {
// may need to increase maxShardsPerNode (e.g. if it was shard split, then now we need more)
restore.setMaxShardsPerNode((int)Math.ceil(backupCollection.getReplicas().size()/cluster.getJettySolrRunners().size()));
@@ -306,6 +316,14 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
v <= restoreCollection.getMaxShardsPerNode());
});
+ assertEquals("Different count of nrtReplicas. Backup collection state=" + backupCollection + "\nRestore " +
+ "collection state=" + restoreCollection, replFactor, restoreCollection.getNumNrtReplicas().intValue());
+ assertEquals("Different count of pullReplicas. Backup collection state=" + backupCollection + "\nRestore" +
+ " collection state=" + restoreCollection, numPullReplicas, restoreCollection.getNumPullReplicas().intValue());
+ assertEquals("Different count of TlogReplica. Backup collection state=" + backupCollection + "\nRestore" +
+ " collection state=" + restoreCollection, numTlogReplicas, restoreCollection.getNumTlogReplicas().intValue());
+
+
// assert added core properties:
// DWS: did via manual inspection.
// TODO Find the applicable core.properties on the file system but how?