SOLR-5525 use hasCollection()

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1553095 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2013-12-23 11:44:21 +00:00
parent 8d9d344501
commit 97d3e2d546
5 changed files with 12 additions and 9 deletions

View File

@ -262,7 +262,7 @@ public class Overseer {
private ClusterState buildCollection(ClusterState clusterState, ZkNodeProps message) {
String collection = message.getStr("name");
log.info("building a new collection: " + collection);
if(clusterState.getCollections().contains(collection) ){
if(clusterState.hasCollection(collection) ){
log.warn("Collection {} already exists. exit" ,collection);
return clusterState;
}

View File

@ -366,8 +366,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
boolean removed = false;
while (System.currentTimeMillis() < timeout) {
Thread.sleep(100);
removed = !zkStateReader.getClusterState().getCollections()
.contains(message.getStr("name"));
removed = !zkStateReader.getClusterState().hasCollection(message.getStr(collection));
if (removed) {
Thread.sleep(100); // just a bit of time so it's more likely other
// readers see on return
@ -609,7 +608,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
}
if (parentSlice == null) {
if(clusterState.getCollections().contains(collectionName)) {
if(clusterState.hasCollection(collectionName)) {
throw new SolrException(ErrorCode.BAD_REQUEST, "No shard with the specified name exists: " + slice);
} else {
throw new SolrException(ErrorCode.BAD_REQUEST, "No collection with the specified name exists: " + collectionName);
@ -1003,7 +1002,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
Slice slice = clusterState.getSlice(collection, sliceId);
if (slice == null) {
if(clusterState.getCollections().contains(collection)) {
if(clusterState.hasCollection(collection)) {
throw new SolrException(ErrorCode.BAD_REQUEST,
"No shard with the specified name exists: " + slice);
} else {
@ -1316,7 +1315,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
}
private void createCollection(ClusterState clusterState, ZkNodeProps message, NamedList results) throws KeeperException, InterruptedException {
String collectionName = message.getStr("name");
if (clusterState.getCollections().contains(collectionName)) {
if (clusterState.hasCollection(collectionName)) {
throw new SolrException(ErrorCode.BAD_REQUEST, "collection already exists: " + collectionName);
}

View File

@ -387,8 +387,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
createNewSolrServer("", baseUrl).request(request);
cloudClient.getZkStateReader().updateClusterState(true);
assertFalse(cloudClient.getZkStateReader().getClusterState()
.getCollections().contains("halfdeletedcollection2"));
assertFalse(cloudClient.getZkStateReader().getClusterState().hasCollection("halfdeletedcollection2"));
}

View File

@ -138,7 +138,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
//printLayout();
// the collection should be gone
timeoutAt = System.currentTimeMillis() + 30000;
while (getCommonCloudSolrServer().getZkStateReader().getClusterState().getCollections().contains(collection)) {
while (getCommonCloudSolrServer().getZkStateReader().getClusterState().hasCollection(collection)) {
if (System.currentTimeMillis() > timeoutAt) {
printLayout();
fail("Still found collection");

View File

@ -146,4 +146,9 @@ public class ZkNodeProps implements JSONWriter.Writable {
return propMap.containsKey(key);
}
public boolean getBool(String key, boolean b) {
Object o = propMap.get(key);
if(o==null) return b;
return Boolean.parseBoolean(o.toString());
}
}