You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by va...@apache.org on 2018/03/14 19:58:43 UTC

lucene-solr:master: SOLR-12083: Fix RealTime GET to work on a cluster running CDCR when using Solr's in-place updates

Repository: lucene-solr
Updated Branches:
  refs/heads/master b7793372a -> 57524f1d4


SOLR-12083: Fix RealTime GET to work on a cluster running CDCR when using Solr's in-place updates


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/57524f1d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/57524f1d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/57524f1d

Branch: refs/heads/master
Commit: 57524f1d4179f3ab57ffa53ba8f5e4dd1e198a11
Parents: b779337
Author: Varun Thacker <va...@apache.org>
Authored: Wed Mar 14 12:58:30 2018 -0700
Committer: Varun Thacker <va...@apache.org>
Committed: Wed Mar 14 12:58:30 2018 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 +++
 .../handler/component/RealTimeGetComponent.java | 15 +++++++++++---
 .../solr/collection1/conf/solrconfig-tlog.xml   |  2 +-
 .../org/apache/solr/search/TestRealTimeGet.java |  1 +
 .../solr/update/TestInPlaceUpdatesDistrib.java  |  2 ++
 .../java/org/apache/solr/SolrTestCaseJ4.java    | 21 +++++++++++++++++++-
 6 files changed, 39 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/57524f1d/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9ba9581..f53b7db 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -318,6 +318,9 @@ Bug Fixes
 * SOLR-12064: JSON Facet API: fix bug where a limit of -1 in conjunction with multiple facets or
   missing=true caused an NPE or AIOOBE. (Karthik Ramachandran via yonik)
 
+* SOLR-12083: Fix RealTime GET to work on a cluster running CDCR when using Solr's in-place updates
+  (Amrit Sarkar, Varun Thacker)
+
 
 Optimizations
 ----------------------

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/57524f1d/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
index 8e3ffeb..6eb89c8 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
@@ -80,6 +80,7 @@ import org.apache.solr.search.SolrDocumentFetcher;
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.search.SolrReturnFields;
 import org.apache.solr.search.SyntaxError;
+import org.apache.solr.update.CdcrUpdateLog;
 import org.apache.solr.update.DocumentBuilder;
 import org.apache.solr.update.IndexFingerprint;
 import org.apache.solr.update.PeerSync;
@@ -255,7 +256,11 @@ public class RealTimeGetComponent extends SearchComponent
                if (oper == UpdateLog.ADD) {
                  doc = toSolrDoc((SolrInputDocument)entry.get(entry.size()-1), core.getLatestSchema());
                } else if (oper == UpdateLog.UPDATE_INPLACE) {
-                 assert entry.size() == 5;
+                 if (ulog instanceof CdcrUpdateLog) {
+                   assert entry.size() == 6;
+                 } else {
+                   assert entry.size() == 5;
+                 }
                  // For in-place update case, we have obtained the partial document till now. We need to
                  // resolve it to a full document to be returned to the user.
                  doc = resolveFullDocument(core, idBytes.get(), rsp.getReturnFields(), (SolrInputDocument)entry.get(entry.size()-1), entry, null);
@@ -395,7 +400,7 @@ public class RealTimeGetComponent extends SearchComponent
    */
   private static SolrDocument resolveFullDocument(SolrCore core, BytesRef idBytes,
                                            ReturnFields returnFields, SolrInputDocument partialDoc, List logEntry, Set<String> onlyTheseFields) throws IOException {
-    if (idBytes == null || logEntry.size() != 5) {
+    if (idBytes == null || (logEntry.size() != 5 && logEntry.size() != 6)) {
       throw new SolrException(ErrorCode.INVALID_STATE, "Either Id field not present in partial document or log entry doesn't have previous version.");
     }
     long prevPointer = (long) logEntry.get(UpdateLog.PREV_POINTER_IDX);
@@ -541,7 +546,11 @@ public class RealTimeGetComponent extends SearchComponent
         }
         switch (oper) {
           case UpdateLog.UPDATE_INPLACE:
-            assert entry.size() == 5;
+            if (ulog instanceof CdcrUpdateLog) {
+              assert entry.size() == 6;
+            } else {
+              assert entry.size() == 5;
+            }
 
             if (resolveFullDocument) {
               SolrInputDocument doc = (SolrInputDocument)entry.get(entry.size()-1);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/57524f1d/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml
----------------------------------------------------------------------
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml
index 10c7ccd..c8884c6 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-tlog.xml
@@ -54,7 +54,7 @@
   </peerSync>
 
   <updateHandler class="solr.DirectUpdateHandler2">
-    <updateLog>
+    <updateLog class="${solr.tests.ulog:solr.UpdateLog}">
       <str name="dir">${solr.ulog.dir:}</str>
       <str name="maxNumLogsToKeep">${solr.ulog.maxNumLogsToKeep:10}</str>
       <str name="numRecordsToKeep">${solr.ulog.numRecordsToKeep:100}</str>

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/57524f1d/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java b/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
index 4ee4cb7..69d34f6 100644
--- a/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
+++ b/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
@@ -42,6 +42,7 @@ public class TestRealTimeGet extends TestRTGBase {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
+    randomizeUpdateLogImpl();
     initCore("solrconfig-tlog.xml","schema_latest.xml");
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/57524f1d/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java
index d01d68f..3818c20 100644
--- a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java
+++ b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java
@@ -81,6 +81,8 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase {
     // asserting inplace updates happen by checking the internal [docid]
     systemSetPropertySolrTestsMergePolicyFactory(NoMergePolicyFactory.class.getName());
 
+    randomizeUpdateLogImpl();
+
     initCore(configString, schemaString);
     
     // sanity check that autocommits are disabled

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/57524f1d/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
----------------------------------------------------------------------
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 e090246..3197d10 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -801,6 +801,11 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
     if (factoryProp == null) {
       System.clearProperty("solr.directoryFactory");
     }
+
+    if (System.getProperty(UPDATELOG_SYSPROP) != null) {
+      // clears the updatelog sysprop at the end of the test run
+      System.clearProperty(UPDATELOG_SYSPROP);
+    }
     
     solrConfig = null;
     h = null;
@@ -2703,7 +2708,21 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
    * @see #randomizeNumericTypesProperties
    */
   public static final String NUMERIC_DOCVALUES_SYSPROP = "solr.tests.numeric.dv";
-  
+
+  public static final String UPDATELOG_SYSPROP = "solr.tests.ulog";
+
+  /**
+   * randomizes the updateLog between different update log implementations for better test coverage
+   */
+  public static void randomizeUpdateLogImpl() {
+    if (random().nextBoolean()) {
+      System.setProperty(UPDATELOG_SYSPROP, "solr.CdcrUpdateLog");
+    } else {
+      System.setProperty(UPDATELOG_SYSPROP,"solr.UpdateLog");
+    }
+    log.info("updateLog impl={}", System.getProperty(UPDATELOG_SYSPROP));
+  }
+
   /**
    * Sets various sys props related to user specified or randomized choices regarding the types 
    * of numerics that should be used in tests.