rdblue commented on a change in pull request #736: Add timeout for acquiring 
locks in HiveTableOperations
URL: https://github.com/apache/incubator-iceberg/pull/736#discussion_r367010124
 
 

 ##########
 File path: hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
 ##########
 @@ -249,13 +257,32 @@ private long acquireLock() throws UnknownHostException, 
TException, InterruptedE
     LockResponse lockResponse = metaClients.run(client -> 
client.lock(lockRequest));
     LockState state = lockResponse.getState();
     long lockId = lockResponse.getLockid();
-    //TODO add timeout
+
+    final long start = System.currentTimeMillis();
+    long duration = 0;
+    boolean timeout = false;
     while (state.equals(LockState.WAITING)) {
       lockResponse = metaClients.run(client -> client.checkLock(lockId));
       state = lockResponse.getState();
+
+      // check timeout
+      duration = System.currentTimeMillis() - start;
+      if (duration > lockAcquireTimeout) {
+        timeout = true;
+        break;
+      }
+
       Thread.sleep(50);
     }
 
+    // timeout and do not have lock acquired
+    if (timeout && !state.equals(LockState.ACQUIRED)) {
+      throw new CommitFailedException(String.format("Timeout when acquiring 
the lock on %s.%s, " +
+          "have waited for %s ms, more than %s ms set by %s",
 
 Review comment:
   How about "Timed out after %s ms waiting for lock on %s.%s"? I don't think 
we need to specify the config property or the timeout threshold.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to