rdblue commented on a change in pull request #1823:
URL: https://github.com/apache/iceberg/pull/1823#discussion_r547526912



##########
File path: 
aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java
##########
@@ -117,9 +120,39 @@ protected void doCommit(TableMetadata base, TableMetadata 
metadata) {
       if (exceptionThrown) {
         io().deleteFile(newMetadataLocation);
       }
+
+      unlock();
+    }
+  }
+
+  private void acquireLock() {
+    try {
+      boolean lockAcquired = lockManager.tryLock(lockId(databaseName, 
tableName),
+          awsProperties.glueCatalogLockExpireMs(), 
awsProperties.glueCatalogLockWaitMs());
+      if (!lockAcquired) {
+        throw new CommitFailedException("Timed out after %s ms waiting for 
lock on %s.%s",
+            awsProperties.glueCatalogLockWaitMs(), databaseName, tableName);
+      }
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new CommitFailedException(e, "Thread interrupted during commit");
+    } catch (Exception e) {
+      throw new CommitFailedException(e, "Unexpected exception when locking 
%s.%s", databaseName, tableName);
     }
   }
 
+  private void unlock() {
+    try {
+      lockManager.unlock(lockId(databaseName, tableName));
+    } catch (Exception e) {
+      LOG.error("Unexpected exception when unlocking {}.{}, manual unlock 
might be needed", databaseName, tableName, e);
+    }
+  }
+
+  private String lockId(String database, String table) {
+    return String.format("%s.%s", database, table);
+  }

Review comment:
       Nit: Rather than creating a new string each time, could you do this once 
in the constructor?




----------------------------------------------------------------
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:
[email protected]



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

Reply via email to