SOLR-9447: Do not clone SolrInputDocument if update processor chain does not contain custom processors.

This commit is contained in:
Shalin Shekhar Mangar 2016-08-31 01:19:42 +05:30
parent 02b97a29b7
commit 26262f4074
2 changed files with 23 additions and 2 deletions

View File

@ -100,6 +100,9 @@ Optimizations
* SOLR-9449: Example schemas do not index _version_ field anymore because the field
has DocValues enabled already. (shalin)
* SOLR-9447: Do not clone SolrInputDocument if update processor chain does not contain custom processors.
(shalin)
Other Changes
----------------------

View File

@ -266,6 +266,11 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
//used for keeping track of replicas that have processed an add/update from the leader
private RequestReplicationTracker replicationTracker = null;
// should we clone the document before sending it to replicas?
// this is set to true in the constructor if the next processors in the chain
// are custom and may modify the SolrInputDocument racing with its serialization for replication
private final boolean cloneRequiredOnLeader;
public DistributedUpdateProcessor(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
this(req, rsp, new AtomicUpdateDocumentMerger(req), next);
}
@ -314,6 +319,19 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
collection = null;
}
boolean shouldClone = false;
UpdateRequestProcessor nextInChain = next;
while (nextInChain != null) {
Class<? extends UpdateRequestProcessor> klass = nextInChain.getClass();
if (klass != LogUpdateProcessorFactory.LogUpdateProcessor.class
&& klass != RunUpdateProcessor.class
&& klass != TolerantUpdateProcessor.class) {
shouldClone = true;
break;
}
nextInChain = nextInChain.next;
}
cloneRequiredOnLeader = shouldClone;
}
private List<Node> setupRequest(String id, SolrInputDocument doc) {
@ -1086,14 +1104,14 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
boolean willDistrib = isLeader && nodes != null && nodes.size() > 0;
SolrInputDocument clonedDoc = null;
if (willDistrib) {
if (willDistrib && cloneRequiredOnLeader) {
clonedDoc = cmd.solrDoc.deepCopy();
}
// TODO: possibly set checkDeleteByQueries as a flag on the command?
doLocalAdd(cmd);
if (willDistrib) {
if (willDistrib && cloneRequiredOnLeader) {
cmd.solrDoc = clonedDoc;
}