You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/02/23 09:01:25 UTC

[GitHub] [iceberg] ZorTsou commented on a change in pull request #2263: Hive: make sure unlock is called when HiveTableOperations can not acq…

ZorTsou commented on a change in pull request #2263:
URL: https://github.com/apache/iceberg/pull/2263#discussion_r580864911



##########
File path: hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
##########
@@ -348,16 +345,15 @@ private long acquireLock() throws UnknownHostException, TException, InterruptedE
                 LOG.warn("Interrupted while waiting for lock.", e);
               }
             }, TException.class);
-      } catch (WaitingForLockException waitingForLockException) {
-        timeout = true;
-        duration = System.currentTimeMillis() - start;
       }
-    }
-
-    // timeout and do not have lock acquired
-    if (timeout && !state.get().equals(LockState.ACQUIRED)) {
+    } catch (WaitingForLockException waitingForLockException) {
+      // timeout and do not have lock acquired
       throw new CommitFailedException("Timed out after %s ms waiting for lock on %s.%s",
-          duration, database, tableName);
+          System.currentTimeMillis() - start, database, tableName);
+    } finally {
+      if (!state.get().equals(LockState.ACQUIRED)) {
+        unlock(Optional.of(lockId));

Review comment:
       While client calling lock, hive metastore creates an exclusive lock with `WAITING` state on the hive table first. If there is no other lock on the table, then metastore changes the state to `ACQUIRED`. Otherwise, updates `hl_blockedby_ext_id` to the latest lockId. No matter whether the lock state is acquired, the lock information will stored in HIVE_LOCKS as below.
   
   hl_lock_ext_id | hl_table | hl_lock_state | hl_lock_type | hl_last_heartbeat | hl_blockedby_ext_id
   -- | -- | -- | -- | -- | --
   1651514 | test_table | a | e | 1614062112285 |  
   1651516 | test_table | w | e | 1614062132342 | 1651514
   1651518 | test_table | w | e | 1614062152426 | 1651516
   
   In this case, a new lock will remain in the waiting state until the latest lock is deleted by client or txn cleanup thread.




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



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