ctubbsii commented on code in PR #5145:
URL: https://github.com/apache/accumulo/pull/5145#discussion_r1873694440


##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ServiceLock.java:
##########
@@ -762,4 +762,26 @@ public static boolean deleteLock(ZooReaderWriter zk, 
ServiceLockPath path, Strin
 
     return false;
   }
+
+  /**
+   * Checks that the lock still exists in ZooKeeper. The typical mechanism for 
determining if a lock
+   * is lost depends on a Watcher set on the lock node. There exists a case 
where the Watcher may
+   * not get called if another Watcher is stuck waiting on I/O or otherwise 
hung. In the case where
+   * this method returns false, then the typical action is to exit the server 
process.
+   *
+   * @return true if lock path still exists, false otherwise and on error
+   */
+  public boolean verifyLockAtSource() {
+    if (getLockPath() == null) {
+      // lock not set yet
+      return false;
+    }
+    try {
+      return null != this.zooKeeper.exists(getLockPath(), false);
+    } catch (KeeperException | InterruptedException e) {

Review Comment:
   If you're worried about RuntimeExceptions, it's better to write it more 
carefully as:
   
   ```suggestion
       } catch (KeeperException | InterruptedException | RuntimeException e) {
   ```
   
   That way, it isn't written so broadly as to fail to catch an unanticipated 
change that introduces a new unhandled checked exception.
   
   However, NPE, specifically isn't possible here, since there's a 
requiresNonNull on the ZK that's passed in, and I don't think getLockPath() can 
throw that either.



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