Apache Lucene open-source search software
SOLR-12083: Fix RealTime GET to work on a cluster running CDCR when using Solr's in-place updates
Varun Thacker57524f1d4179
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 9ba9581d02f..f53b7db46ad 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 ormissing=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----------------------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.javaindex 8e3ffebd849..6eb89c8561b 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 SearchComponentif (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);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.xmlindex 10c7ccdf995..c8884c6363f 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>diff --git a/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java b/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.javaindex 4ee4cb70afb..69d34f60bbb 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 {@BeforeClasspublic static void beforeClass() throws Exception {+ randomizeUpdateLogImpl();initCore("solrconfig-tlog.xml","schema_latest.xml");}diff --git a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.javaindex d01d68f4269..3818c20e017 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 disableddiff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex e090246d5f2..3197d1028ef 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.