You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/02/12 07:43:00 UTC

[GitHub] [lucene-solr] sarkaramrit2 commented on a change in pull request #1167: SOLR-13845: DELETEREPLICA API by count and type

sarkaramrit2 commented on a change in pull request #1167: SOLR-13845: DELETEREPLICA API by count and type
URL: https://github.com/apache/lucene-solr/pull/1167#discussion_r378082629
 
 

 ##########
 File path: solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteReplicaCmd.java
 ##########
 @@ -187,44 +201,66 @@ void deleteReplicaBasedOnCount(ClusterState clusterState,
    * Validate if there is less replicas than requested to remove. Also error out if there is
    * only one replica available
    */
-  private void validateReplicaAvailability(Slice slice, String shard, String collectionName, int count) {
+  private void validateReplicaAvailability(Slice slice, String shard, String collectionName, int count, Replica.Type type) {
     //If there is a specific shard passed, validate if there any or just 1 replica left
     if (slice != null) {
       Collection<Replica> allReplicasForShard = slice.getReplicas();
       if (allReplicasForShard == null) {
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No replicas found  in shard/collection: " +
-                shard + "/"  + collectionName);
+            shard + "/" + collectionName);
       }
 
+      if (type == null) {
+        if (allReplicasForShard.size() == 1) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There is only one replica available in shard/collection: " +
+              shard + "/" + collectionName + ". Cannot delete that.");
+        }
 
-      if (allReplicasForShard.size() == 1) {
-        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There is only one replica available in shard/collection: " +
-                shard + "/" + collectionName + ". Cannot delete that.");
-      }
-
-      if (allReplicasForShard.size() <= count) {
-        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There are lesser num replicas requested to be deleted than are available in shard/collection : " +
-                shard + "/"  + collectionName  + " Requested: "  + count + " Available: " + allReplicasForShard.size() + ".");
+        if (allReplicasForShard.size() <= count) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There are lesser num replicas requested to be deleted than are available in shard/collection : " +
+              shard + "/" + collectionName + " Requested: " + count + " Available: " + allReplicasForShard.size() + ".");
+        }
+      } else {
+        int nrtReplicas = slice.getReplicas(EnumSet.of(Replica.Type.NRT)).size();
+        int pullReplicas = slice.getReplicas(EnumSet.of(Replica.Type.PULL)).size();
+        int tlogReplicas = slice.getReplicas(EnumSet.of(Replica.Type.TLOG)).size();
+
+        if (type.equals(Replica.Type.PULL)) {
+          if (pullReplicas < count) {
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There are lesser num replicas requested to be deleted than are available in type/shard/collection : " +
+                type + "/" + shard + "/" + collectionName + " Requested: " + count + " Available: " + pullReplicas + ".");
+          }
+        } else if (type.equals(Replica.Type.NRT)) {
+          if (nrtReplicas <= count && tlogReplicas < 1) {
+            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There are lesser num replicas or qualified leaders requested to be deleted than are available in shard/collection : " +
+                shard + "/" + collectionName + " Requested: " + count + " Available: " + nrtReplicas + ".");
+          }
+        } else if (type.equals(Replica.Type.TLOG)) {
 
 Review comment:
   Thanks, @anshumg for the review. The checks are in place to avoid such a situation where we delete the only qualified leaders. 
   
   Are you suggesting parallel delete-by-count-and-type requests can create such a situation where we delete all qualified leaders? The replica count is read from Clusterstate, where we have the appropriate read-write lock, so the logic should be good. Let me know if I am missing a piece.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org