You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/07/30 19:04:13 UTC

[GitHub] [accumulo] Manno15 commented on a diff in pull request #2817: Adding TabletServerLocks utility to accumulo admin command

Manno15 commented on code in PR #2817:
URL: https://github.com/apache/accumulo/pull/2817#discussion_r933878018


##########
server/base/src/main/java/org/apache/accumulo/server/util/TabletServerLocks.java:
##########
@@ -41,38 +41,50 @@ static class Opts extends Help {
     String delete = null;
   }
 
-  public static void main(String[] args) throws Exception {
-
-    try (var context = new ServerContext(SiteConfiguration.auto())) {
-      String tserverPath = context.getZooKeeperRoot() + Constants.ZTSERVERS;
-      Opts opts = new Opts();
-      opts.parseArgs(TabletServerLocks.class.getName(), args);
+  public static void tabletServerLocks(String commandName, final ServerContext context,
+      final String lock, final boolean list, final String delete) throws Exception {
 
-      ZooCache cache = context.getZooCache();
-      ZooReaderWriter zoo = context.getZooReaderWriter();
+    String tserverPath = context.getZooKeeperRoot() + Constants.ZTSERVERS;
 
-      if (opts.list) {
+    ZooCache cache = context.getZooCache();
+    ZooReaderWriter zoo = context.getZooReaderWriter();
 
-        List<String> tabletServers = zoo.getChildren(tserverPath);
+    if (list) {
+      List<String> tabletServers = zoo.getChildren(tserverPath);
 
-        for (String tabletServer : tabletServers) {
-          var zLockPath = ServiceLock.path(tserverPath + "/" + tabletServer);
-          byte[] lockData = ServiceLock.getLockData(cache, zLockPath, null);
-          String holder = null;
-          if (lockData != null) {
-            holder = new String(lockData, UTF_8);
-          }
-
-          System.out.printf("%32s %16s%n", tabletServer, holder);
+      for (String tabletServer : tabletServers) {
+        var zLockPath = ServiceLock.path(tserverPath + "/" + tabletServer);
+        byte[] lockData = ServiceLock.getLockData(cache, zLockPath, null);
+        String holder = null;
+        if (lockData != null) {
+          holder = new String(lockData, UTF_8);
         }
-      } else if (opts.delete != null) {
-        ServiceLock.deleteLock(zoo, ServiceLock.path(tserverPath + "/" + args[1]));
-      } else {
-        System.out.println(
-            "Usage : " + TabletServerLocks.class.getName() + " -list|-delete <tserver lock>");
+
+        System.out.printf("%32s %16s%n", tabletServer, holder);
       }
+    } else if (delete != null) {
+      if (lock == null) {
+        printUsage(commandName);
+      }
+      ServiceLock.deleteLock(zoo, ServiceLock.path(tserverPath + "/" + lock));
+    } else {
+      printUsage(commandName);
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
 
+    try (var context = new ServerContext(SiteConfiguration.auto())) {

Review Comment:
   Should this command also aim to refactor the use of SiteConfiguration like in issue #2155?



-- 
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: notifications-unsubscribe@accumulo.apache.org

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