From 1d7379b680062eca766f0410e3db7ff9e9b34cb0 Mon Sep 17 00:00:00 2001 From: Chris Hostetter Date: Mon, 9 Jan 2017 09:53:55 -0700 Subject: [PATCH] SOLR-9934: SolrTestCase.clearIndex has been improved to take advantage of low level test specific logic that clears the index metadata more completely then a normal *:* DBQ can due to update versioning --- solr/CHANGES.txt | 3 +++ .../org/apache/solr/search/TestRTGBase.java | 12 ---------- .../org/apache/solr/search/TestRecovery.java | 13 ----------- .../apache/solr/search/TestRecoveryHdfs.java | 11 ---------- .../apache/solr/update/CdcrUpdateLogTest.java | 17 -------------- .../java/org/apache/solr/SolrTestCaseJ4.java | 22 +++++++++++++++++-- 6 files changed, 23 insertions(+), 55 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 49d24df19c1..b28df9c5d82 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -408,6 +408,9 @@ Other Changes * SOLR-9777: IndexFingerprinting should use getCombinedCoreAndDeletesKey() instead of getCoreCacheKey() for per-segment caching (Ishan Chattopadhyaya) +* SOLR-9934: SolrTestCase.clearIndex has been improved to take advantage of low level test specific logic that + clears the index metadata more completely then a normal *:* DBQ can due to update versioning. (hossman) + ================== 6.3.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/search/TestRTGBase.java b/solr/core/src/test/org/apache/solr/search/TestRTGBase.java index 13ecb32e9a7..bb1b08a04a5 100644 --- a/solr/core/src/test/org/apache/solr/search/TestRTGBase.java +++ b/solr/core/src/test/org/apache/solr/search/TestRTGBase.java @@ -36,24 +36,12 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.update.UpdateLog; import static org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase; -import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM; public class TestRTGBase extends SolrTestCaseJ4 { // means we've seen the leader and have version info (i.e. we are a non-leader replica) public static String FROM_LEADER = DistribPhase.FROMLEADER.toString(); - // since we make up fake versions in these tests, we can get messed up by a DBQ with a real version - // since Solr can think following updates were reordered. - @Override - public void clearIndex() { - try { - deleteByQueryAndGetVersion("*:*", params("_version_", Long.toString(-Long.MAX_VALUE), DISTRIB_UPDATE_PARAM,FROM_LEADER)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - protected final ConcurrentHashMap model = new ConcurrentHashMap<>(); protected Map committedModel = new HashMap<>(); protected long snapshotCount; diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.java index 12d3ec33b9a..9b88ec4343a 100644 --- a/solr/core/src/test/org/apache/solr/search/TestRecovery.java +++ b/solr/core/src/test/org/apache/solr/search/TestRecovery.java @@ -72,19 +72,6 @@ public class TestRecovery extends SolrTestCaseJ4 { } } - - // since we make up fake versions in these tests, we can get messed up by a DBQ with a real version - // since Solr can think following updates were reordered. - @Override - public void clearIndex() { - try { - deleteByQueryAndGetVersion("*:*", params("_version_", Long.toString(-Long.MAX_VALUE), DISTRIB_UPDATE_PARAM,FROM_LEADER)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Test public void testLogReplay() throws Exception { try { diff --git a/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java b/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java index e7e60eca5fc..e6bb9a6edb0 100644 --- a/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java +++ b/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java @@ -109,17 +109,6 @@ public class TestRecoveryHdfs extends SolrTestCaseJ4 { dfsCluster = null; } - // since we make up fake versions in these tests, we can get messed up by a DBQ with a real version - // since Solr can think following updates were reordered. - @Override - public void clearIndex() { - try { - deleteByQueryAndGetVersion("*:*", params("_version_", Long.toString(-Long.MAX_VALUE), DISTRIB_UPDATE_PARAM,FROM_LEADER)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - @Test public void testReplicationFactor() throws Exception { clearIndex(); diff --git a/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java b/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java index 60dc9c3eaaf..b7409d10e45 100644 --- a/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java +++ b/solr/core/src/test/org/apache/solr/update/CdcrUpdateLogTest.java @@ -31,20 +31,14 @@ import org.apache.lucene.util.LuceneTestCase.Nightly; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.request.SolrQueryRequest; -import org.apache.solr.update.processor.DistributedUpdateProcessor; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.noggit.ObjectBuilder; -import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM; - @Nightly public class CdcrUpdateLogTest extends SolrTestCaseJ4 { - // means that we've seen the leader and have version info (i.e. we are a non-leader replica) - private static String FROM_LEADER = DistributedUpdateProcessor.DistribPhase.FROMLEADER.toString(); - private static int timeout = 60; // acquire timeout in seconds. change this to a huge number when debugging to prevent threads from advancing. // TODO: fix this test to not require FSDirectory @@ -66,17 +60,6 @@ public class CdcrUpdateLogTest extends SolrTestCaseJ4 { } } - // since we make up fake versions in these tests, we can get messed up by a DBQ with a real version - // since Solr can think following updates were reordered. - @Override - public void clearIndex() { - try { - deleteByQueryAndGetVersion("*:*", params("_version_", Long.toString(-Long.MAX_VALUE), DISTRIB_UPDATE_PARAM, FROM_LEADER)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - private void clearCore() throws IOException { clearIndex(); assertU(commit()); diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java index 437679db08f..61de56dddb6 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -132,6 +132,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; +import static org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase; +import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM; + import static java.util.Objects.requireNonNull; /** @@ -1148,9 +1151,24 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { @Override public String toString() { return xml; } } - + + /** + * Does a low level delete of all docs in the index. + * + * The behavior of this method is slightly different then doing a normal *:* DBQ because it + * takes advantage of internal methods to ensure all index data is wiped, regardless of optimistic + * concurrency version constraints -- making it suitable for tests that create synthetic versions, + * and/or require a completely pristine index w/o any field metdata. + * + * @see #deleteByQueryAndGetVersion + */ public void clearIndex() { - assertU(delQ("*:*")); + try { + deleteByQueryAndGetVersion("*:*", params("_version_", Long.toString(-Long.MAX_VALUE), + DISTRIB_UPDATE_PARAM,DistribPhase.FROMLEADER.toString())); + } catch (Exception e) { + throw new RuntimeException(e); + } } /** Send JSON update commands */