slfan1989 commented on code in PR #13795:
URL: https://github.com/apache/iceberg/pull/13795#discussion_r2280317880


##########
flink/v2.0/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java:
##########
@@ -126,29 +159,46 @@ public void close() throws IOException {
       if (client != null) {
         client.close();
       }
+      isOpen = false;
     }
   }
 
   /** Zookeeper lock implementation */
   private static class ZkLock implements Lock {
     private final SharedCount sharedCount;
+    private final String lockId;
+    private final String lockType;
+    private final String lockPath;
+
+    private static final int LOCKED = 1;
+    private static final int UNLOCKED = 0;
 
-    private ZkLock(SharedCount sharedCount) {
+    private ZkLock(String lockId, String lockType, String lockPath, 
SharedCount sharedCount) {
+      this.lockId = lockId;
+      this.lockType = lockType;
+      this.lockPath = lockPath;
       this.sharedCount = sharedCount;
     }
 
     @Override
     public boolean tryLock() {
       VersionedValue<Integer> versionedValue = sharedCount.getVersionedValue();
       if (isHeld(versionedValue)) {
-        LOG.debug("Lock is already held for {}", this);
+        LOG.debug(
+            "Lock is already held for lockId: {}, type: {}, path: {}.", 
lockId, lockType, lockPath);
         return false;
       }
 
       try {
-        return sharedCount.trySetCount(versionedValue, LOCKED);
+        boolean acquired = sharedCount.trySetCount(versionedValue, LOCKED);
+        if (!acquired) {
+          LOG.warn(
+              "Failed to acquire {} lock for lockId: {}, path: {}", lockType, 
lockId, lockPath);
+        }
+
+        return acquired;
       } catch (Exception e) {
-        LOG.debug("Failed to acquire Zookeeper lock ", e);
+        LOG.error("Failed to acquire Zookeeper lock.", e);

Review Comment:
   Thank you for raising this question!
   
   In the `tryLock` method, regarding exception handling: the 
`sharedCount.trySetCount` call internally catches 
`KeeperException.BadVersionException` and returns `false`, thereby handling the 
expected case of version mismatch. 
   
   For the specific implementation, you can refer to the code of SharedValue in 
Apache Curator (SharedCount is based on this implementation), with the link as 
follows:
   
https://github.com/apache/curator/blob/28291442ebd843c474533be4894462ae317d9a5c/curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java#L168-L206
   
   Additionally, this method may also throw other subclasses of 
`KeeperException`, such as `ConnectionLossException`, 
`SessionExpiredException`, or `NoNodeException`. 
   
   These typically involve unexpected errors related to ZooKeeper's 
connectivity, session issues, or node status. 
   
   From my perspective, logging these exceptions at the ERROR level is more 
appropriate, as it helps diagnose potential ZooKeeper problems; if logged only 
at the DEBUG level, these errors might be overlooked.
   
   In addition, the link to logging best practices you provided was very 
helpful!



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to