SOLR-8804: Fix a race condition in the ClusterStatus API call

This commit is contained in:
Varun Thacker 2016-03-11 14:01:01 +05:30
parent b0caca3b60
commit 343d9c6fa4
3 changed files with 34 additions and 4 deletions

View File

@ -289,6 +289,9 @@ Bug Fixes
* SOLR-8790: Collections API responses contain node name in the core-level responses that are
returned. (Anshum Gupta)
* SOLR-8804: Fix a race condition in the ClusterStatus API call whereby the call would fail when a concurrent delete
collection api command was executed (Alexey Serba, Varun Thacker)
Optimizations
----------------------
* SOLR-7876: Speed up queries and operations that use many terms when timeAllowed has not been

View File

@ -89,7 +89,7 @@ public class ClusterStatus {
byte[] bytes = Utils.toJSON(clusterState);
Map<String, Object> stateMap = (Map<String,Object>) Utils.fromJSON(bytes);
Set<String> collections = new HashSet<>();
Set<String> collections;
String routeKey = message.getStr(ShardParams._ROUTE_);
String shard = message.getStr(ZkStateReader.SHARD_ID_PROP);
if (collection == null) {
@ -98,11 +98,19 @@ public class ClusterStatus {
collections = Collections.singleton(collection);
}
NamedList<Object> collectionProps = new SimpleOrderedMap<Object>();
NamedList<Object> collectionProps = new SimpleOrderedMap<>();
for (String name : collections) {
Map<String, Object> collectionStatus = null;
DocCollection clusterStateCollection = clusterState.getCollection(name);
Map<String, Object> collectionStatus;
DocCollection clusterStateCollection = clusterState.getCollectionOrNull(name);
if (clusterStateCollection == null) {
if (collection != null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Collection: " + name + " not found");
} else {
//collection might have got deleted at the same time
continue;
}
}
Set<String> requestedShards = new HashSet<>();
if (routeKey != null) {

View File

@ -77,6 +77,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
clusterStatusWithRouteKey();
clusterStatusAliasTest();
clusterStatusRolesTest();
clusterStatusBadCollectionTest();
replicaPropTest();
clusterStatusZNodeVersion();
testClusterStateMigration();
@ -318,6 +319,24 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
}
}
private void clusterStatusBadCollectionTest() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", "bad_collection_name");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
try {
client.request(request);
fail("Collection does not exist. An exception should be thrown");
} catch (SolrException e) {
//expected
assertTrue(e.getMessage().contains("Collection: bad_collection_name not found"));
}
}
}
private void replicaPropTest() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
client.connect();