Apache Solr open-source search software
SOLR-4795: Sub shard leader should not accept any updates from parent after it goes active
Shalin Shekhar Mangar3ffb10b13eae
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 17967f7f9c7..baff5e25325 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -90,6 +90,9 @@ Bug Fixes* SOLR-4616: HitRatio on caches is now exposed over JMX MBeans as a float.(Greg Bowyer)+* SOLR-4795: Sub shard leader should not accept any updates from parent after+ it goes active (shalin)+Other Changes----------------------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 80be09e001e..f940489cae7 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@@ -322,7 +322,11 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {boolean localIsLeader = cloudDescriptor.isLeader();if (DistribPhase.FROMLEADER == phase && localIsLeader && from != null) { // from will be null on log replayString fromShard = req.getParams().get("distrib.from.parent");- if (fromShard != null) {+ if (fromShard != null) {+ if (!Slice.CONSTRUCTION.equals(mySlice.getState())) {+ throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,+ "Request says it is coming from parent shard leader but we are not in construction state");+ }// shard splitting case -- check ranges to see if we are a sub-shardSlice fromSlice = zkController.getClusterState().getCollection(collection).getSlice(fromShard);DocRouter.Range parentRange = fromSlice.getRange();@@ -331,12 +335,12 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,"Request says it is coming from parent shard leader but parent hash range is not superset of my range");}- } else {- log.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");- }+ } else {+ log.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");+ }}-+if (isLeader && !localIsLeader) {log.error("ClusterState says we are the leader, but locally we don't think so");throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "ClusterState says we are the leader, but locally we don't think so");diff --git a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.javaindex 9347d76b89b..b0ff4f266a7 100644--- a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java@@ -85,7 +85,8 @@ public class ChaosMonkeyShardSplitTest extends ShardSplitTest {indexThread = new Thread() {@Overridepublic void run() {- for (int id = 101; id < atLeast(401); id++) {+ int max = atLeast(401);+ for (int id = 101; id < max; id++) {try {indexAndUpdateCount(ranges, docCounts, id);Thread.sleep(atLeast(25));diff --git a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.javaindex 35e4e581b2d..4fbe081d228 100644--- a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java@@ -110,7 +110,8 @@ public class ShardSplitTest extends BasicDistributedZkTest {Thread indexThread = new Thread() {@Overridepublic void run() {- for (int id = 101; id < atLeast(401); id++) {+ int max = atLeast(401);+ for (int id = 101; id < max; id++) {try {indexAndUpdateCount(ranges, docCounts, id);Thread.sleep(atLeast(25));