junlong-gao commented on code in PR #1007:
URL: https://github.com/apache/helix/pull/1007#discussion_r425390436


##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java:
##########
@@ -573,35 +573,41 @@ public void resetPartition(String clusterName, String 
instanceName, String resou
     // check the instance is alive
     LiveInstance liveInstance = 
accessor.getProperty(keyBuilder.liveInstance(instanceName));
     if (liveInstance == null) {
-      throw new HelixException(
-          "Can't reset state for " + resourceName + "/" + partitionNames + " 
on " + instanceName
-              + ", because " + instanceName + " is not alive");
+      // check if the instance has never exist in the cluster
+      String instancePath = PropertyPathBuilder.instance(clusterName, 
instanceName);
+      String errMessage;
+      if (!_zkClient.exists(instancePath)) {
+        errMessage = String.format(
+            "Can't reset state for %s.%s on %s, because %s has never existed" 
+ " in cluster %s",
+            resourceName, partitionNames, instanceName, instanceName, 
clusterName);
+      } else {
+        errMessage = String.format("Can't reset state for %s.%s on %s, because 
%s does not live in"
+                + " cluster %s anymore", resourceName, partitionNames, 
instanceName, instanceName,
+            clusterName);
+      }
+      throw new HelixException(errMessage);
     }
 
     // check resource group exists
     IdealState idealState = 
accessor.getProperty(keyBuilder.idealStates(resourceName));
     if (idealState == null) {
-      throw new HelixException(
-          "Can't reset state for " + resourceName + "/" + partitionNames + " 
on " + instanceName
-              + ", because " + resourceName + " is not added");
+      throw new HelixException(String
+          .format("Can't reset state for %s.%s on %s, because %s is not 
added", resourceName,
+              partitionNames, instanceName, resourceName));
     }
 
     // check partition exists in resource group
     Set<String> resetPartitionNames = new HashSet<String>(partitionNames);
+    Set<String> partitions;

Review Comment:
   Looks like either branch of the below if/else needs this, might as well just 
init `partitions` here?
   
   Also, since the original code makes a copy, better keep the original 
semantics here to prevent accidental mutation.
   
   Junlong
   : )



##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java:
##########
@@ -573,35 +573,41 @@ public void resetPartition(String clusterName, String 
instanceName, String resou
     // check the instance is alive
     LiveInstance liveInstance = 
accessor.getProperty(keyBuilder.liveInstance(instanceName));
     if (liveInstance == null) {
-      throw new HelixException(
-          "Can't reset state for " + resourceName + "/" + partitionNames + " 
on " + instanceName
-              + ", because " + instanceName + " is not alive");
+      // check if the instance has never exist in the cluster
+      String instancePath = PropertyPathBuilder.instance(clusterName, 
instanceName);
+      String errMessage;
+      if (!_zkClient.exists(instancePath)) {
+        errMessage = String.format(
+            "Can't reset state for %s.%s on %s, because %s has never existed" 
+ " in cluster %s",
+            resourceName, partitionNames, instanceName, instanceName, 
clusterName);
+      } else {
+        errMessage = String.format("Can't reset state for %s.%s on %s, because 
%s does not live in"
+                + " cluster %s anymore", resourceName, partitionNames, 
instanceName, instanceName,
+            clusterName);
+      }
+      throw new HelixException(errMessage);
     }
 
     // check resource group exists
     IdealState idealState = 
accessor.getProperty(keyBuilder.idealStates(resourceName));
     if (idealState == null) {
-      throw new HelixException(
-          "Can't reset state for " + resourceName + "/" + partitionNames + " 
on " + instanceName
-              + ", because " + resourceName + " is not added");
+      throw new HelixException(String
+          .format("Can't reset state for %s.%s on %s, because %s is not 
added", resourceName,
+              partitionNames, instanceName, resourceName));
     }
 
     // check partition exists in resource group
     Set<String> resetPartitionNames = new HashSet<String>(partitionNames);
+    Set<String> partitions;

Review Comment:
   Looks like there is a slight difference `getMapFields` vs `getListFields` 
requires this if-else, so perhaps a ternary operator or the current if-else is 
already unavoidable.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org

Reply via email to