Skip to content

Apache Lucene open-source search software

SOLR-2592: cleanups - remove unneeded range info, rename getLeaderProps to getLeaderRetry

Yonik Seeleyc02c9dd26282
diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java
index 2236aa65f64..14775a8dc1d 100644
--- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java
+++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java
@@ -318,7 +318,7 @@ public class RecoveryStrategy extends Thread implements ClosableThread {
try {
CloudDescriptor cloudDesc = core.getCoreDescriptor()
.getCloudDescriptor();
- ZkNodeProps leaderprops = zkStateReader.getLeaderProps(
+ ZkNodeProps leaderprops = zkStateReader.getLeaderRetry(
cloudDesc.getCollectionName(), cloudDesc.getShardId());
String leaderBaseUrl = leaderprops.getStr(ZkStateReader.BASE_URL_PROP);
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.java
index cd8ade929c9..0bfe12015a6 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
@@ -210,7 +210,7 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
// Not equivalent to getLeaderProps, which does retries to find a leader.
// Replica leader = slice.getLeader();
- ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(zkController.getZkStateReader().getLeaderProps(
+ ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(zkController.getZkStateReader().getLeaderRetry(
collection, shardId));
String leaderNodeName = leaderProps.getCoreNodeName();
@@ -294,7 +294,7 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
try {
- ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(zkController.getZkStateReader().getLeaderProps(
+ ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(zkController.getZkStateReader().getLeaderRetry(
collection, shardId));
String leaderNodeName = leaderProps.getCoreNodeName();
@@ -774,7 +774,7 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
String sliceName = slice.getName();
Replica leader;
try {
- leader = zkController.getZkStateReader().getLeaderProps(collection, sliceName);
+ leader = zkController.getZkStateReader().getLeaderRetry(collection, sliceName);
} catch (InterruptedException e) {
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Exception finding leader for shard " + sliceName, e);
}
@@ -1113,7 +1113,7 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
public boolean checkRetry() {
ZkCoreNodeProps leaderProps;
try {
- leaderProps = new ZkCoreNodeProps(zkStateReader.getLeaderProps(
+ leaderProps = new ZkCoreNodeProps(zkStateReader.getLeaderRetry(
collection, shardId));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
index b30bada7cd2..943e2799d6b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
@@ -110,7 +110,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
// TODO: bring this to it's own method?
// try indexing to a leader that has no replicas up
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
- ZkNodeProps leaderProps = zkStateReader.getLeaderProps(
+ ZkNodeProps leaderProps = zkStateReader.getLeaderRetry(
DEFAULT_COLLECTION, SHARD2);
String nodeName = leaderProps.getStr(ZkStateReader.NODE_NAME_PROP);
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
index e838b398ef2..f41ddac5b11 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
@@ -165,7 +165,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
// make sure we have leaders for each shard
for (int j = 1; j < sliceCount; j++) {
- zkStateReader.getLeaderProps(DEFAULT_COLLECTION, "shard" + j, 10000);
+ zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + j, 10000);
} // make sure we again have leaders for each shard
waitForRecoveriesToFinish(false);
@@ -530,7 +530,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
}
// ensure there is a leader
- zkStateReader.getLeaderProps("unloadcollection", "shard1", 15000);
+ zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
addClient = new HttpSolrServer(url2 + "/unloadcollection2");
// add a few docs while the leader is down
@@ -572,7 +572,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
}
}
- zkStateReader.getLeaderProps("unloadcollection", "shard1", 15000);
+ zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
// set this back
@@ -677,7 +677,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
ChaosMonkey.start(cloudJettys.get(0).jetty);
cloudClient.getZkStateReader().updateClusterState(true);
try {
- cloudClient.getZkStateReader().getLeaderProps("multiunload2", "shard1", 30000);
+ cloudClient.getZkStateReader().getLeaderRetry("multiunload2", "shard1", 30000);
} catch (SolrException e) {
printLayout();
throw e;
diff --git a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java
index 1b5295966cb..d9698d6bde6 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java
@@ -86,7 +86,7 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
// make sure we have leaders for each shard
for (int j = 1; j < sliceCount; j++) {
- zkStateReader.getLeaderProps(DEFAULT_COLLECTION, "shard" + j, 10000);
+ zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + j, 10000);
} // make sure we again have leaders for each shard
waitForRecoveriesToFinish(false);
@@ -156,7 +156,7 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase
// make sure we again have leaders for each shard
for (int j = 1; j < sliceCount; j++) {
- zkStateReader.getLeaderProps(DEFAULT_COLLECTION, "shard" + j, 10000);
+ zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + j, 10000);
}
commit();
diff --git a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java
index f07f61987bf..22898f63593 100644
--- a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java
@@ -132,7 +132,7 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
private void testThatCantForwardToLeaderFails() throws Exception {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
- ZkNodeProps props = zkStateReader.getLeaderProps(DEFAULT_COLLECTION, "shard1");
+ ZkNodeProps props = zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard1");
chaosMonkey.stopShard("shard1");
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
index 733a32ec807..6dd4b1aea40 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java
@@ -256,7 +256,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
private String getLeader() throws InterruptedException {
- ZkNodeProps props = reader.getLeaderProps("collection1", "shard1", 30000);
+ ZkNodeProps props = reader.getLeaderRetry("collection1", "shard1", 30000);
String leader = props.getStr(ZkStateReader.NODE_NAME_PROP);
return leader;
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
index c7a9c5900c1..164be383c04 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
@@ -50,8 +50,6 @@ public class ClusterState implements JSONWriter.Writable {
private final Map<String, DocCollection> collectionStates; // Map<collectionName, Map<sliceName,Slice>>
private final Set<String> liveNodes;
- private final Map<String,RangeInfo> rangeInfos = new HashMap<String,RangeInfo>();
-
/**
* Use this constr when ClusterState is meant for publication.
*
@@ -72,12 +70,11 @@ public class ClusterState implements JSONWriter.Writable {
this.liveNodes.addAll(liveNodes);
this.collectionStates = new HashMap<String, DocCollection>(collectionStates.size());
this.collectionStates.putAll(collectionStates);
- addRangeInfos(collectionStates.keySet());
}
/**
- * Get properties of a shard/slice leader for specific collection, or null if one currently doesn't exist.
+ * Get the lead replica for specific collection, or null if one currently doesn't exist.
*/
public Replica getLeader(String collection, String sliceName) {
DocCollection coll = collectionStates.get(collection);
@@ -88,7 +85,7 @@ public class ClusterState implements JSONWriter.Writable {
}
/**
- * Get replica properties (if the slice is unknown) or null if replica is not found.
+ * Gets the replica by the core name (assuming the slice is unknown) or null if replica is not found.
* If the slice is known, do not use this method.
* coreNodeName is the same as replicaName
*/
@@ -105,14 +102,9 @@ public class ClusterState implements JSONWriter.Writable {
return null;
}
- private void addRangeInfos(Set<String> collections) {
- for (String collection : collections) {
- addRangeInfo(collection);
- }
- }
/**
- * Get the Slice for collection.
+ * Get the named Slice for collection, or null if not found.
*/
public Slice getSlice(String collection, String sliceName) {
DocCollection coll = collectionStates.get(collection);
@@ -184,34 +176,6 @@ public class ClusterState implements JSONWriter.Writable {
public boolean liveNodesContain(String name) {
return liveNodes.contains(name);
}
-
- public RangeInfo getRanges(String collection) {
- // TODO: store this in zk
- RangeInfo rangeInfo = rangeInfos.get(collection);
-
- return rangeInfo;
- }
-
- private RangeInfo addRangeInfo(String collection) {
- List<Range> ranges;
- RangeInfo rangeInfo;
- rangeInfo = new RangeInfo();
-
- DocCollection coll = getCollection(collection);
-
- Set<String> shards = coll.getSlicesMap().keySet();
- ArrayList<String> shardList = new ArrayList<String>(shards.size());
- shardList.addAll(shards);
- Collections.sort(shardList);
-
- ranges = DocRouter.DEFAULT.partitionRange(shards.size(), Integer.MIN_VALUE, Integer.MAX_VALUE);
-
- rangeInfo.ranges = ranges;
- rangeInfo.shardList = shardList;
- rangeInfos.put(collection, rangeInfo);
- return rangeInfo;
- }
-
@Override
public String toString() {
@@ -290,11 +254,6 @@ public class ClusterState implements JSONWriter.Writable {
public void write(JSONWriter jsonWriter) {
jsonWriter.write(collectionStates);
}
-
- private class RangeInfo {
- private List<Range> ranges;
- private ArrayList<String> shardList;
- }
/**
* The version of clusterstate.json in ZooKeeper.
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index 6abf0179e6f..3afea751a67 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -393,7 +393,7 @@ public class ZkStateReader {
public String getLeaderUrl(String collection, String shard, int timeout)
throws InterruptedException, KeeperException {
- ZkCoreNodeProps props = new ZkCoreNodeProps(getLeaderProps(collection,
+ ZkCoreNodeProps props = new ZkCoreNodeProps(getLeaderRetry(collection,
shard, timeout));
return props.getCoreUrl();
}
@@ -401,14 +401,14 @@ public class ZkStateReader {
/**
* Get shard leader properties, with retry if none exist.
*/
- public Replica getLeaderProps(String collection, String shard) throws InterruptedException {
- return getLeaderProps(collection, shard, 1000);
+ public Replica getLeaderRetry(String collection, String shard) throws InterruptedException {
+ return getLeaderRetry(collection, shard, 1000);
}
/**
* Get shard leader properties, with retry if none exist.
*/
- public Replica getLeaderProps(String collection, String shard, int timeout) throws InterruptedException {
+ public Replica getLeaderRetry(String collection, String shard, int timeout) throws InterruptedException {
long timeoutAt = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < timeoutAt) {
if (clusterState != null) {
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
index 7f62c9aad7f..9479da600a0 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
@@ -111,7 +111,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
ZkStateReader zkStateReader = ((SolrDispatchFilter) jettys.get(0)
.getDispatchFilter().getFilter()).getCores().getZkController()
.getZkStateReader();
- zkStateReader.getLeaderProps("collection1", "shard" + (i + 2), 15000);
+ zkStateReader.getLeaderRetry("collection1", "shard" + (i + 2), 15000);
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index 73b11bc2065..e3abf2a8836 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.lucene.util.LuceneTestCase.Slow;
-import org.apache.solr.BaseDistributedSearchTestCase.RandVal;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
@@ -53,12 +52,10 @@ import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.zookeeper.KeeperException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -323,7 +320,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
// also make sure we have a leader for each shard
for (int i = 1; i <= sliceCount; i++) {
- zkStateReader.getLeaderProps(DEFAULT_COLLECTION, "shard" + i, 10000);
+ zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + i, 10000);
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
index b6d9329c964..5ee57b118c4 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
@@ -347,7 +347,7 @@ public class ChaosMonkey {
ZkNodeProps leader = null;
try {
- leader = zkStateReader.getLeaderProps(collection, slice);
+ leader = zkStateReader.getLeaderRetry(collection, slice);
} catch (Throwable t) {
log.error("Could not get leader", t);
return null;