ctubbsii commented on a change in pull request #2175:
URL: https://github.com/apache/accumulo/pull/2175#discussion_r656606594



##########
File path: 
server/manager/src/main/java/org/apache/accumulo/manager/tableOps/Utils.java
##########
@@ -153,6 +155,58 @@ public static void unreserveHdfsDirectory(Manager env, 
String directory, long ti
         String.format("%016x", tid));
   }
 
+  private static boolean hasReadLock(ServerContext context, AbstractId<?> id, 
long tid)
+      throws KeeperException, InterruptedException {
+    byte[] lockData = String.format("%016x", tid).getBytes(UTF_8);
+    var fLockPath =
+        FateLock.path(context.getZooKeeperRoot() + Constants.ZTABLE_LOCKS + 
"/" + id.canonical());
+    FateLock qlock = new FateLock(context.getZooReaderWriter(), fLockPath);
+    Lock lock = DistributedReadWriteLock.recoverLock(qlock, lockData);
+    if (lock == null) {
+      return false;
+    } else if (lock instanceof ReadLock) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  public static boolean hasNamespaceReadLock(Manager env, NamespaceId nsId, 
long tid)
+      throws KeeperException, InterruptedException {
+    return hasReadLock(env.getContext(), nsId, tid);
+  }
+
+  public static boolean hasTableReadLock(Manager env, TableId tableId, long 
tid)
+      throws KeeperException, InterruptedException {
+    return hasReadLock(env.getContext(), tableId, tid);
+  }
+
+  private static boolean hasWriteLock(ServerContext context, AbstractId<?> id, 
long tid)
+      throws KeeperException, InterruptedException {
+    byte[] lockData = String.format("%016x", tid).getBytes(UTF_8);
+    var fLockPath =
+        FateLock.path(context.getZooKeeperRoot() + Constants.ZTABLE_LOCKS + 
"/" + id.canonical());
+    FateLock qlock = new FateLock(context.getZooReaderWriter(), fLockPath);
+    Lock lock = DistributedReadWriteLock.recoverLock(qlock, lockData);
+    if (lock == null) {
+      return false;
+    } else if (lock instanceof WriteLock) {
+      return true;
+    } else {
+      return false;
+    }
+  }

Review comment:
       This method duplicates a lot of code with the other private method for 
checking the read lock. These could be consolidated, and the other methods 
could pass a boolean to indicate if the read or write lock is being checked. 
This is similar to the other implementations in this class, except it's even 
better, because the boolean would only be exposed in the private method.




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


Reply via email to