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

This commit is contained in:
Varun Thacker 2018-03-14 12:58:30 -07:00
parent b7793372a9
commit 57524f1d41
6 changed files with 39 additions and 5 deletions

View File

@ -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
----------------------

View File

@ -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);

View File

@ -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>

View File

@ -42,6 +42,7 @@ public class TestRealTimeGet extends TestRTGBase {
@BeforeClass
public static void beforeClass() throws Exception {
randomizeUpdateLogImpl();
initCore("solrconfig-tlog.xml","schema_latest.xml");
}

View File

@ -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

View File

@ -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.