rsingh433 commented on code in PR #4125:
URL: https://github.com/apache/accumulo/pull/4125#discussion_r1443066852


##########
server/manager/src/main/java/org/apache/accumulo/manager/tableOps/Utils.java:
##########
@@ -166,8 +168,17 @@ private static Lock getLock(ServerContext context, 
AbstractId<?> id, long tid,
     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) {
+    DistributedLock lock = DistributedReadWriteLock.recoverLock(qlock, 
lockData);
+    if (lock != null) {
+
+      // Validate the recovered lock type
+      boolean isWriteLock = lock.getType() == LockType.WRITE;

Review Comment:
   ```
   private static Lock getLock(ServerContext context, AbstractId<?> id, long 
tid,
         LockType lockType) {
       byte[] lockData = FastFormat.toZeroPaddedHex(tid);
       var fLockPath =
           FateLock.path(context.getZooKeeperRoot() + Constants.ZTABLE_LOCKS + 
"/" + id.canonical());
       FateLock qlock = new FateLock(context.getZooReaderWriter(), fLockPath);
       DistributedLock lock = DistributedReadWriteLock.recoverLock(qlock, 
lockData);
       if (lock != null) {
   
         // Validate the recovered lock type
         if (lock.getType() != lockType) {
           throw new IllegalStateException("Unexpected lock type " + 
lock.getType()
               + " recovered for transaction " + FateTxId.formatTid(tid) + " on 
object " + id
               + ". Expected " + lockType + " lock instead.");
         }
       } else {
         DistributedReadWriteLock locker = new DistributedReadWriteLock(qlock, 
lockData);
         if (lockType == LockType.WRITE) {
           lock = locker.writeLock();
         } else {
           lock = locker.readLock();
         }
       }
       return lock;
     }
   ```
   
   Maybe with this change, the method is more flexible, and you can pass the 
desired LockType directly instead of using a boolean parameter. Any suggestions?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to