This is an automated email from the ASF dual-hosted git repository.

cshannon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new 4055d696c5 Improve output and user experience of accumulo admin 
utilities (#2992)
4055d696c5 is described below

commit 4055d696c52ce8c67076b024cbc0922fb4dcdbe1
Author: Christopher L. Shannon <christopher.l.shan...@gmail.com>
AuthorDate: Tue Oct 4 15:11:26 2022 -0400

    Improve output and user experience of accumulo admin utilities (#2992)
    
    * Update DeleteZooInstance to prompt user to confirm if trying to delete
    the current instance
    * Update TabletServerLocks to display <none> instead of null if no locks
    for the tablet server
    
    This is a follow on to #2807
---
 .../accumulo/server/util/DeleteZooInstance.java    | 41 +++++++++++++++++-----
 .../accumulo/server/util/TabletServerLocks.java    |  9 +++--
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java
 
b/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java
index 9ec844f902..11ee77617f 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java
@@ -56,12 +56,12 @@ public class DeleteZooInstance {
     } else {
       // If all old is false then we require a specific instance
       Objects.requireNonNull(instance, "Instance name must not be null");
-      removeInstance(zk, instance);
+      removeInstance(context, zk, instance);
     }
   }
 
-  private static void removeInstance(final ZooReaderWriter zk, final String 
instance)
-      throws InterruptedException, KeeperException {
+  private static void removeInstance(ServerContext context, final 
ZooReaderWriter zk,
+      final String instance) throws InterruptedException, KeeperException {
     // try instance name:
     Set<String> instances = new HashSet<>(getInstances(zk));
     Set<String> uuids = new HashSet<>(zk.getChildren(Constants.ZROOT));
@@ -69,16 +69,25 @@ public class DeleteZooInstance {
     if (instances.contains(instance)) {
       String path = getInstancePath(instance);
       byte[] data = zk.getData(path);
-      deleteRetry(zk, path);
-      deleteRetry(zk, getRootChildPath(new String(data, UTF_8)));
-      System.out.println("Deleted instance: " + instance);
+      if (data != null) {
+        final String instanceId = new String(data, UTF_8);
+        if (checkCurrentInstance(context, instance, instanceId)) {
+          deleteRetry(zk, path);
+          deleteRetry(zk, getRootChildPath(instanceId));
+          System.out.println("Deleted instance: " + instance);
+        }
+      }
     } else if (uuids.contains(instance)) {
       // look for the real instance name
       for (String zkInstance : instances) {
         String path = getInstancePath(zkInstance);
         byte[] data = zk.getData(path);
-        if (instance.equals(new String(data, UTF_8))) {
-          deleteRetry(zk, path);
+        if (data != null) {
+          final String instanceId = new String(data, UTF_8);
+          if (instance.equals(instanceId) && checkCurrentInstance(context, 
instance, instanceId)) {
+            deleteRetry(zk, path);
+            System.out.println("Deleted instance: " + instance);
+          }
         }
       }
       deleteRetry(zk, getRootChildPath(instance));
@@ -103,6 +112,22 @@ public class DeleteZooInstance {
     }
   }
 
+  private static boolean checkCurrentInstance(ServerContext context, String 
instanceName,
+      String instanceId) {
+    boolean operate = true;
+    // If the instance given is the current instance we should verify the user 
actually wants to
+    // delete
+    if (instanceId.equals(context.getInstanceID().canonical())) {
+      String line = String.valueOf(System.console()
+          .readLine("Warning: This is the current instance, are you sure? 
(yes|no): "));
+      operate = line != null && (line.equalsIgnoreCase("y") || 
line.equalsIgnoreCase("yes"));
+      if (!operate) {
+        System.out.println("Instance deletion of '" + instanceName + "' 
cancelled.");
+      }
+    }
+    return operate;
+  }
+
   private static String getRootChildPath(String child) {
     return Constants.ZROOT + "/" + child;
   }
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/util/TabletServerLocks.java
 
b/server/base/src/main/java/org/apache/accumulo/server/util/TabletServerLocks.java
index bb5b26fe85..669aa1820a 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/util/TabletServerLocks.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/util/TabletServerLocks.java
@@ -46,9 +46,11 @@ public class TabletServerLocks {
       for (String tabletServer : tabletServers) {
         var zLockPath = ServiceLock.path(tserverPath + "/" + tabletServer);
         byte[] lockData = ServiceLock.getLockData(cache, zLockPath, null);
-        String holder = null;
+        final String holder;
         if (lockData != null) {
           holder = new String(lockData, UTF_8);
+        } else {
+          holder = "<none>";
         }
 
         System.out.printf("%32s %16s%n", tabletServer, holder);
@@ -57,7 +59,10 @@ public class TabletServerLocks {
       if (lock == null) {
         printUsage();
       }
-      ServiceLock.deleteLock(zoo, ServiceLock.path(tserverPath + "/" + lock));
+
+      ServiceLock.ServiceLockPath path = ServiceLock.path(tserverPath + "/" + 
lock);
+      ServiceLock.deleteLock(zoo, path);
+      System.out.printf("Deleted %s", path);
     }
   }
 

Reply via email to