Apache Solr open-source search software
SOLR-5593: Replicas should accept the last updates from a leader that has just lost it's connection to ZooKeeper.
Mark Robert Millera2bf844c90af
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 9e1cfde86b3..ebae0d33d1d 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -270,6 +270,9 @@ Bug Fixes* SOLR-5598: LanguageIdentifierUpdateProcessor ignores all but the first valueof multiValued string fields. (Andreas Hubold, Vitaliy Zhovtyuk via shalin)+* SOLR-5593: Replicas should accept the last updates from a leader that has just+ lost it's connection to ZooKeeper. (Christine Poerschke via Mark Miller)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.javaindex d9e1c6a046b..8483b62a55d 100644--- a/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java+++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java@@ -228,6 +228,19 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {}}+ DistribPhase phase =+ DistribPhase.parseParam(req.getParams().get(DISTRIB_UPDATE_PARAM));++ if (DistribPhase.FROMLEADER == phase && !couldIbeSubShardLeader(coll)) {+ if (req.getCore().getCoreDescriptor().getCloudDescriptor().isLeader()) {+ // locally we think we are leader but the request says it came FROMLEADER+ // that could indicate a problem, let the full logic below figure it out+ } else {+ isLeader = false; // we actually might be the leader, but we don't want leader-logic for these types of updates anyway.+ forwardToLeader = false;+ return nodes;+ }+ }String shardId = slice.getName();@@ -251,9 +264,6 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {}}- DistribPhase phase =- DistribPhase.parseParam(req.getParams().get(DISTRIB_UPDATE_PARAM));-doDefensiveChecks(phase);// if request is coming from another collection then we want it to be sent to all replicas@@ -314,11 +324,21 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {return nodes;}+ private boolean couldIbeSubShardLeader(DocCollection coll) {+ // Could I be the leader of a shard in "construction/recovery" state?+ String myShardId = req.getCore().getCoreDescriptor().getCloudDescriptor()+ .getShardId();+ Slice mySlice = coll.getSlice(myShardId);+ String state = mySlice.getState();+ return (Slice.CONSTRUCTION.equals(state) || Slice.RECOVERY.equals(state));+ }+private boolean amISubShardLeader(DocCollection coll, Slice parentSlice, String id, SolrInputDocument doc) throws InterruptedException {- // Am I the leader of a shard in "construction" state?+ // Am I the leader of a shard in "construction/recovery" state?String myShardId = req.getCore().getCoreDescriptor().getCloudDescriptor().getShardId();Slice mySlice = coll.getSlice(myShardId);- if (Slice.CONSTRUCTION.equals(mySlice.getState()) || Slice.RECOVERY.equals(mySlice.getState())) {+ String state = mySlice.getState();+ if (Slice.CONSTRUCTION.equals(state) || Slice.RECOVERY.equals(state)) {Replica myLeader = zkController.getZkStateReader().getLeaderRetry(collection, myShardId);boolean amILeader = myLeader.getName().equals(req.getCore().getCoreDescriptor().getCloudDescriptor()