Skip to content

Apache Lucene open-source search software

SOLR-7173: Fix ReplicationFactorTest on Windows

Timothy Potterf3bc0ad73153
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index d7eaf6ff289..e960c9380df 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -307,6 +307,9 @@ Other Changes
* SOLR-7180: MiniSolrCloudCluster will startup and shutdown its jetties in
parallel (Alan Woodward, Tomás Fernández Löbbe, Vamsee Yarlagadda)
+* SOLR-7173: Fix ReplicationFactorTest on Windows by adding better retry
+ support after seeing no response exceptions. (Ishan Chattopadhyaya via Timothy Potter)
+
================== 5.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java
index 7d27950498c..3cefb476019 100644
--- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java
@@ -48,6 +48,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -473,38 +474,15 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
String url = zkProps.getBaseUrl() + "/" + coll;
return new HttpSolrClient(url);
}
-
- protected void doSendDoc(int docid) throws Exception {
- UpdateRequest up = new UpdateRequest();
- up.setParam(UpdateRequest.MIN_REPFACT, String.valueOf(2));
- SolrInputDocument doc = new SolrInputDocument();
- doc.addField(id, String.valueOf(docid));
- doc.addField("a_t", "hello" + docid);
- up.add(doc);
- int minAchievedRf =
- cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), cloudClient.request(up));
- }
-
+
protected void sendDoc(int docId) throws Exception {
- try {
- doSendDoc(docId);
- } catch (SolrServerException e) {
- if (e.getRootCause() instanceof NoHttpResponseException) {
- // we don't know if the doc was accepted or not, we send again
- Thread.sleep(100);
- try {
- doSendDoc(docId);
- } catch (SolrServerException e2) {
- if (e2.getRootCause() instanceof NoHttpResponseException) {
- // we don't know if the doc was accepted or not, we send again
- Thread.sleep(3000);
- doSendDoc(docId);
- }
- }
- }
- }
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField(id, String.valueOf(docId));
+ doc.addField("a_t", "hello" + docId);
+
+ sendDocsWithRetry(Collections.singletonList(doc), 2, 3, 100);
}
-
+
/**
* Query the real-time get handler for a specific doc by ID to verify it
* exists in the provided server, using distrib=false so it doesn't route to another replica.
diff --git a/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java b/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java
index bb948255498..08b7edc12d7 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java
@@ -30,6 +30,7 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkCoreNodeProps;
@@ -258,11 +259,7 @@ public class ReplicationFactorTest extends AbstractFullDistribZkTestBase {
batch.add(doc);
}
- UpdateRequest up = new UpdateRequest();
- up.setParam(UpdateRequest.MIN_REPFACT, String.valueOf(minRf));
- up.add(batch);
- int batchRf =
- cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), cloudClient.request(up));
+ int batchRf = sendDocsWithRetry(batch, minRf, 5, 1);
assertRf(3, "batch should have succeeded on all replicas", batchRf);
// add some chaos to the batch
@@ -276,12 +273,8 @@ public class ReplicationFactorTest extends AbstractFullDistribZkTestBase {
doc.addField("a_t", "hello" + i);
batch.add(doc);
}
-
- up = new UpdateRequest();
- up.setParam(UpdateRequest.MIN_REPFACT, String.valueOf(minRf));
- up.add(batch);
- batchRf =
- cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), cloudClient.request(up));
+
+ batchRf = sendDocsWithRetry(batch, minRf, 5, 1);
assertRf(2, "batch should have succeeded on 2 replicas (only one replica should be down)", batchRf);
// close the 2nd replica, and send a 3rd batch with expected achieved rf=1
@@ -294,12 +287,8 @@ public class ReplicationFactorTest extends AbstractFullDistribZkTestBase {
doc.addField("a_t", "hello" + i);
batch.add(doc);
}
-
- up = new UpdateRequest();
- up.setParam(UpdateRequest.MIN_REPFACT, String.valueOf(minRf));
- up.add(batch);
- batchRf =
- cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), cloudClient.request(up));
+
+ batchRf = sendDocsWithRetry(batch, minRf, 5, 1);
assertRf(1, "batch should have succeeded on the leader only (both replicas should be down)", batchRf);
getProxyForReplica(replicas.get(0)).reopen();
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index 7f667d1d902..17000fccf5d 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -778,6 +778,30 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
+ @SuppressWarnings("rawtypes")
+ protected int sendDocsWithRetry(List<SolrInputDocument> batch, int minRf, int maxRetries, int waitBeforeRetry) throws Exception {
+ UpdateRequest up = new UpdateRequest();
+ up.setParam(UpdateRequest.MIN_REPFACT, String.valueOf(minRf));
+ up.add(batch);
+ NamedList resp = null;
+ int numRetries = 0;
+ while(true) {
+ try {
+ resp = cloudClient.request(up);
+ return cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), resp);
+ } catch (Exception exc) {
+ Throwable rootCause = SolrException.getRootCause(exc);
+ if (++numRetries <= maxRetries) {
+ log.warn("ERROR: " + rootCause + " ... Sleeping for " + waitBeforeRetry + " seconds before re-try ...");
+ Thread.sleep(waitBeforeRetry * 1000L);
+ } else {
+ log.error("No more retries available! Add batch failed due to: " + rootCause);
+ throw exc;
+ }
+ }
+ }
+ }
+
@Override
protected void indexDoc(SolrInputDocument doc) throws IOException,
SolrServerException {