shounakmk219 commented on code in PR #10969:
URL: https://github.com/apache/pinot/pull/10969#discussion_r1245149485


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java:
##########
@@ -3148,6 +3137,31 @@ public PinotResourceManagerResponse dropInstance(String 
instanceName) {
     return PinotResourceManagerResponse.success("Instance " + instanceName + " 
dropped");
   }
 
+  /**
+   * Utility to perform a safety check of the operation to drop an instance.
+   * If the resource is not safe to drop the utility lists all the possible 
reasons.
+   * @param instanceName Pinot instance name
+   * @return List of reasons why the operation is unsafe. Empty list if the 
operation is safe.
+   */
+  public List<String> instanceDropSafetyCheck(String instanceName) {
+    List<String> issues = new ArrayList<>();
+    // Check if the instance is live
+    if (_helixDataAccessor.getProperty(_keyBuilder.liveInstance(instanceName)) 
!= null) {
+      issues.add(String.format("Instance %s is still live", instanceName));
+    }
+    // Check if any ideal state includes the instance
+    getAllResources().forEach(resource -> {
+      IdealState idealState = 
_helixAdmin.getResourceIdealState(_helixClusterName, resource);
+      for (String partition : idealState.getPartitionSet()) {
+        if (idealState.getInstanceSet(partition).contains(instanceName)) {
+          issues.add(String.format("Instance %s exists in ideal state for %s", 
instanceName, resource));
+          break;

Review Comment:
   We are just early terminating the loop on resource partitions, like even if 
one segment is present on the instance mark it as unsafe saying that particular 
table is on that instance. The outer loop will still check for all the tables 
and give a comprehensive list of issues at table level. 



-- 
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: commits-unsubscr...@pinot.apache.org

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


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

Reply via email to