Apache Solr open-source search software
SOLR-4257: PeerSync updates and Log Replay updates should not wait for ZK connection
Yonik Seeleyc7d885205182
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex e6ecefa1ec4..5ab7a23786c 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -435,6 +435,9 @@ Bug Fixes* SOLR-4253: Misleading resource loading warning from Carrot2 clusteringcomponent fixed (Stanisław Osiński)+* SOLR-4257: PeerSync updates and Log Replay updates should not wait for+ a ZooKeeper connection in order to proceed. (yonik)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/update/PeerSync.java b/solr/core/src/java/org/apache/solr/update/PeerSync.javaindex 867cb91c76f..bd3fd1e5cab 100644--- a/solr/core/src/java/org/apache/solr/update/PeerSync.java+++ b/solr/core/src/java/org/apache/solr/update/PeerSync.java@@ -443,10 +443,11 @@ public class PeerSync {ModifiableSolrParams params = new ModifiableSolrParams();params.set(DISTRIB_UPDATE_PARAM, FROMLEADER.toString());- // params.set("peersync",true); // debugging+ params.set("peersync",true); // debuggingSolrQueryRequest req = new LocalSolrQueryRequest(uhandler.core, params);SolrQueryResponse rsp = new SolrQueryResponse();+ // TODO: use the standard update processor chain now that it has support to skip processors before the DistributedUpdateProcessor?RunUpdateProcessorFactory runFac = new RunUpdateProcessorFactory();DistributedUpdateProcessorFactory magicFac = new DistributedUpdateProcessorFactory();runFac.init(new NamedList());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 083bba8536c..4b9461f7d52 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@@ -140,6 +140,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {private int numNodes;+ private UpdateCommand updateCommand; // the current command this processor is working on.+public DistributedUpdateProcessor(SolrQueryRequest req,SolrQueryResponse rsp, UpdateRequestProcessor next) {@@ -184,6 +186,12 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {// if we are in zk mode...if (zkEnabled) {+ if ((updateCommand.getFlags() & (UpdateCommand.REPLAY | UpdateCommand.PEER_SYNC)) != 0) {+ 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 coreName = req.getCore().getName();String coreNodeName = zkController.getNodeName() + "_" + coreName;@@ -272,10 +280,12 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {private void doDefensiveChecks(String shardId, DistribPhase phase) {+ boolean isReplayOrPeersync = (updateCommand.getFlags() & (UpdateCommand.REPLAY | UpdateCommand.REPLAY)) != 0;+ if (isReplayOrPeersync) return;+String from = req.getParams().get("distrib.from");- boolean logReplay = req.getParams().getBool(LOG_REPLAY, false);boolean localIsLeader = req.getCore().getCoreDescriptor().getCloudDescriptor().isLeader();- if (!logReplay && DistribPhase.FROMLEADER == phase && localIsLeader && from != null) { // from will be null on log replay+ if (DistribPhase.FROMLEADER == phase && localIsLeader && from != null) { // from will be null on log replaylog.error("Request says it is coming from leader, but we are the leader: " + req.getParamString());throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Request says it is coming from leader, but we are the leader");}@@ -326,6 +336,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {@Overridepublic void processAdd(AddUpdateCommand cmd) throws IOException {+ updateCommand = cmd;+if (zkEnabled) {zkCheck();nodes = setupRequest(cmd.getHashableId(), cmd.getSolrInputDocument());@@ -493,8 +505,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {}}- boolean isReplay = (cmd.getFlags() & UpdateCommand.REPLAY) != 0;- boolean leaderLogic = isLeader && !isReplay;+ boolean isReplayOrPeersync = (cmd.getFlags() & (UpdateCommand.REPLAY | UpdateCommand.REPLAY)) != 0;+ boolean leaderLogic = isLeader && !isReplayOrPeersync;VersionBucket bucket = vinfo.bucket(bucketHash);@@ -690,6 +702,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {@Overridepublic void processDelete(DeleteUpdateCommand cmd) throws IOException {+ updateCommand = cmd;+if (!cmd.isDeleteById()) {doDeleteByQuery(cmd);return;@@ -848,8 +862,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {}versionOnUpdate = Math.abs(versionOnUpdate); // normalize to positive version- boolean isReplay = (cmd.getFlags() & UpdateCommand.REPLAY) != 0;- boolean leaderLogic = isLeader && !isReplay;+ boolean isReplayOrPeersync = (cmd.getFlags() & (UpdateCommand.REPLAY | UpdateCommand.REPLAY)) != 0;+ boolean leaderLogic = isLeader && !isReplayOrPeersync;if (!leaderLogic && versionOnUpdate==0) {throw new SolrException(ErrorCode.BAD_REQUEST, "missing _version_ on update from leader");@@ -912,6 +926,11 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {private void zkCheck() {+ if ((updateCommand.getFlags() & (UpdateCommand.REPLAY | UpdateCommand.PEER_SYNC)) != 0) {+ // for log reply or peer sync, we don't need to be connected to ZK+ return;+ }+if (zkController.isConnected()) {return;}@@ -955,8 +974,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {long signedVersionOnUpdate = versionOnUpdate;versionOnUpdate = Math.abs(versionOnUpdate); // normalize to positive version- boolean isReplay = (cmd.getFlags() & UpdateCommand.REPLAY) != 0;- boolean leaderLogic = isLeader && !isReplay;+ boolean isReplayOrPeersync = (cmd.getFlags() & (UpdateCommand.REPLAY | UpdateCommand.REPLAY)) != 0;+ boolean leaderLogic = isLeader && !isReplayOrPeersync;if (!leaderLogic && versionOnUpdate==0) {throw new SolrException(ErrorCode.BAD_REQUEST, "missing _version_ on update from leader");@@ -1026,6 +1045,8 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {@Overridepublic void processCommit(CommitUpdateCommand cmd) throws IOException {+ updateCommand = cmd;+if (zkEnabled) {zkCheck();}