CaoManhDat 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_r381003552
 
 

 ##########
 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();
+
 
 Review comment:
   we do not always need to compute these 3 variables all the time, so it can 
be computed later after we look into type.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to