:SOLR-13454: Investigate ReindexCollectionTest failures, added more safeguards in bandaid code

This commit is contained in:
Erick Erickson 2019-09-29 12:25:43 -04:00
parent 2ba61c8fb9
commit 4f89987141
1 changed files with 37 additions and 2 deletions

View File

@ -121,6 +121,7 @@ import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.ObjectReleaseTracker;
import org.apache.solr.common.util.SolrjNamedThreadFactory;
import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.common.util.Utils;
import org.apache.solr.common.util.XML;
import org.apache.solr.core.CoreContainer;
@ -152,6 +153,7 @@ import org.apache.solr.util.SSLTestConfig;
import org.apache.solr.util.StartupLoggingUtils;
import org.apache.solr.util.TestHarness;
import org.apache.solr.util.TestInjection;
import org.apache.solr.util.TimeOut;
import org.apache.zookeeper.KeeperException;
import org.junit.After;
import org.junit.AfterClass;
@ -3116,7 +3118,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
QueryResponse rsp = client.query(collection, solrQuery);
long found = rsp.getResults().getNumFound();
if (rsp.getResults().getNumFound() == expectedDocCount) {
if (found == expectedDocCount) {
return;
}
@ -3131,9 +3133,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
// Add the bogus doc
new UpdateRequest().add(bogus).commit(client, collection);
// Let's spin until we find the doc.
checkUniqueDoc(client, collection, idField, bogusID, true);
// Then remove it, we should be OK now since new searchers have been opened.
new UpdateRequest().deleteById(bogusID).commit(client, collection);
// Let's check again to see if we succeeded
// Now spin until the doc is gone.
checkUniqueDoc(client, collection, idField, bogusID, false);
// At this point we're absolutely, totally, positive that a new searcher has been opened, so go ahead and check
// the actual condition.
rsp = client.query(collection, solrQuery);
found = rsp.getResults().getNumFound();
@ -3145,6 +3155,31 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
} else if (failAnyway) {
fail("Solr11035BandAid failAnyway == true, would have successfully repaired the collection: '" + collection
+ "' extra info: '" + tag + "'");
} else {
log.warn("Solr11035BandAid, repair successful");
}
}
// Helper for bandaid
private static void checkUniqueDoc(SolrClient client, String collection, String idField, String id, boolean shouldBeThere) throws IOException, SolrServerException {
TimeOut timeOut = new TimeOut(100, TimeUnit.SECONDS, TimeSource.NANO_TIME);
final SolrQuery solrQuery = new SolrQuery(idField + ":" + id);
while (!timeOut.hasTimedOut()) {
QueryResponse rsp = client.query(collection, solrQuery);
long found = rsp.getResults().getNumFound();
if (shouldBeThere && found == 1) {
return;
}
if (shouldBeThere == false && found == 0) {
return;
}
log.warn("Solr11035BandAid should have succeeded in checkUniqueDoc, shouldBeThere == {}, numFound = {}. Will try again after 250 ms sleep", shouldBeThere, found);
try {
Thread.sleep(250);
} catch (InterruptedException e) {
return; // just bail
}
}
}
}