RussellSpitzer commented on a change in pull request #2328:
URL: https://github.com/apache/iceberg/pull/2328#discussion_r593559972



##########
File path: 
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
##########
@@ -217,11 +239,40 @@ protected void doCommit(TableMetadata base, TableMetadata 
metadata) {
       throw new RuntimeException("Interrupted during commit", e);
 
     } finally {
-      cleanupMetadataAndUnlock(threw, newMetadataLocation, lockId);
+      cleanupMetadataAndUnlock(commitStatus, newMetadataLocation, lockId);
+    }
+  }
+
+  /**
+   * Attempt to load the table and see if any current or past metadata 
location matches the one we were attempting
+   * to set. This is used as a last resort when we are dealing with exceptions 
that may indicate the commit has
+   * failed but are not proof that this is the case. Past locations must also 
be searched on the chance that a second
+   * committer was able to successfully commit on top of our commit.
+   *
+   * @param newMetadataLocation the path of the new commit file
+   * @return Commit Status of Success, Failure or Unknown
+   */
+  private CommitStatus checkCommitStatus(String newMetadataLocation) {
+    try {
+      TableMetadata metadata = refresh();
+      String metadataLocation = metadata.metadataFileLocation();
+      boolean commitSuccess = metadataLocation.equals(newMetadataLocation) ||
+          metadata.previousFiles().stream().anyMatch(log -> 
log.file().equals(newMetadataLocation));
+      if (commitSuccess) {
+        LOG.info("Commit status check: Commit of {} succeeded", 
newMetadataLocation);
+        return CommitStatus.SUCCESS;
+      } else {
+        LOG.info("Commit status check: Commit of {} failed", 
newMetadataLocation);
+        return CommitStatus.FAILURE;
+      }
+    } catch (Throwable checkFailure) {
+      LOG.error("Cannot check if commit exists, treating commit state as 
unknown", checkFailure);
+      return CommitStatus.UNKNOWN;
     }
   }
 
-  private void persistTable(Table hmsTable, boolean updateHiveTable) throws 
TException, InterruptedException {
+  // Visible for testing
+  protected void persistTable(Table hmsTable, boolean updateHiveTable) throws 
TException, InterruptedException {

Review comment:
       Required so I can mock this method in the test cases and inject errors




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