pvary commented on code in PR #6451:
URL: https://github.com/apache/iceberg/pull/6451#discussion_r1063348799


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -606,20 +630,13 @@ private StorageDescriptor storageDescriptor(TableMetadata 
metadata, boolean hive
     return storageDescriptor;
   }
 
-  @SuppressWarnings("ReverseDnsLookup")
   @VisibleForTesting
-  long acquireLock() throws UnknownHostException, TException, 
InterruptedException {
-    final LockComponent lockComponent =
-        new LockComponent(LockType.EXCLUSIVE, LockLevel.TABLE, database);
-    lockComponent.setTablename(tableName);
-    final LockRequest lockRequest =
-        new LockRequest(
-            Lists.newArrayList(lockComponent),
-            System.getProperty("user.name"),
-            InetAddress.getLocalHost().getHostName());
-    LockResponse lockResponse = metaClients.run(client -> 
client.lock(lockRequest));
-    AtomicReference<LockState> state = new 
AtomicReference<>(lockResponse.getState());
-    long lockId = lockResponse.getLockid();
+  long acquireLock(String agentInfo) throws UnknownHostException, TException, 
InterruptedException {
+    AtomicReference<Long> lockId = new AtomicReference<>();
+    AtomicReference<LockState> state = new AtomicReference<>();
+
+    // This will set the lockId and state if successful
+    tryLock(agentInfo, lockId, state);

Review Comment:
   Done



##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -699,18 +717,53 @@ private void cleanupMetadataAndUnlock(
     } catch (RuntimeException e) {
       LOG.error("Failed to cleanup metadata file at {}", metadataLocation, e);
     } finally {
-      unlock(lockId);
+      unlock(lockId, agentInfo);
       tableLevelMutex.unlock();
     }
   }
 
-  private void unlock(Optional<Long> lockId) {
-    if (lockId.isPresent()) {
-      try {
-        doUnlock(lockId.get());
-      } catch (Exception e) {
-        LOG.warn("Failed to unlock {}.{}", database, tableName, e);
+  private void unlock(Optional<Long> lockId, String agentInfo) {
+    Long id = null;
+    try {
+      if (!lockId.isPresent()) {
+        // Try to find the lock based on agentInfo. Only works with Hive 2 or 
later.
+        if (MetastoreClientVersion.min(MetastoreClientVersion.HIVE_2)) {
+          AtomicReference<Long> foundLockId = new AtomicReference<>();
+          AtomicReference<LockState> state = new AtomicReference<>();
+          if (!findLock(agentInfo, foundLockId, state)) {

Review Comment:
   Done



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