You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2016/03/12 01:27:21 UTC

[40/50] [abbrv] lucene-solr git commit: SOLR-8804: Fix a race condition in the ClusterStatus API call

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


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/343d9c6f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/343d9c6f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/343d9c6f

Branch: refs/heads/jira/SOLR-445
Commit: 343d9c6fa4ccff3d997b5b8c143b839364569ae6
Parents: b0caca3
Author: Varun Thacker <va...@gmail.com>
Authored: Fri Mar 11 14:01:01 2016 +0530
Committer: Varun Thacker <va...@gmail.com>
Committed: Fri Mar 11 14:02:06 2016 +0530

----------------------------------------------------------------------
 solr/CHANGES.txt                                 |  3 +++
 .../apache/solr/handler/admin/ClusterStatus.java | 16 ++++++++++++----
 .../org/apache/solr/cloud/TestCollectionAPI.java | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/343d9c6f/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4e969bf..1d91a3e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/343d9c6f/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java b/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
index ff60adc..63044fa 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
@@ -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) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/343d9c6f/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
index 45b6f73..dec2bf5 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
@@ -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();