RussellSpitzer commented on a change in pull request #2328:
URL: https://github.com/apache/iceberg/pull/2328#discussion_r592871815
##########
File path:
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java
##########
@@ -199,25 +201,63 @@ protected void doCommit(TableMetadata base, TableMetadata
metadata) {
setHmsTableParameters(newMetadataLocation, tbl, metadata.properties(),
removedProps, hiveEngineEnabled);
persistTable(tbl, updateHiveTable);
- threw = false;
} catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {
- throw new AlreadyExistsException("Table already exists: %s.%s",
database, tableName);
+ commitFailed = true;
+ throw new CommitFailedException("Table already exists: %s.%s", database,
tableName);
} catch (TException | UnknownHostException e) {
if (e.getMessage() != null && e.getMessage().contains("Table/View
'HIVE_LOCKS' does not exist")) {
+ commitFailed = true;
throw new RuntimeException("Failed to acquire locks from metastore
because 'HIVE_LOCKS' doesn't " +
"exist, this probably happened when using embedded metastore or
doesn't create a " +
"transactional meta table. To fix this, use an alternative
metastore", e);
}
- throw new RuntimeException(String.format("Metastore operation failed for
%s.%s", database, tableName), e);
+ RuntimeException metastoreException =
+ new RuntimeException(String.format("Metastore operation failed
for %s.%s", database, tableName), e);
+ if (checkCommitSuccessful(newMetadataLocation, metastoreException)) {
+ return; // We are able to verify the commit succeed
+ } else {
+ // We were able to check and the commit did not succeed
+ commitFailed = true;
+ throw metastoreException;
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- throw new RuntimeException("Interrupted during commit", e);
-
+ RuntimeException interruptException = new RuntimeException("Interrupted
during commit", e);
+ if (checkCommitSuccessful(newMetadataLocation, interruptException)) {
+ return; // We are able to verify the commit succeed
+ } else {
+ // We were able to check and the commit did not succeed
+ commitFailed = true;
+ throw interruptException;
+ }
} finally {
- cleanupMetadataAndUnlock(threw, newMetadataLocation, lockId);
+ cleanupMetadataAndUnlock(commitFailed, newMetadataLocation, lockId);
+ }
+ }
+
+ /**
+ * Attempt to load the table and see if the current metadata location
matches our new commit path. This as used as
+ * a last resort when we are dealing with exceptions which may indicate that
our commit has failed but we are not
+ * certain if that is the case.
+ * @param newMetadataLocation the path of the new commit file
+ * @param originalFailure the exception which leads us to believe the commit
has failed
+ * @return true if the commit was successful, false if not, and rethrows the
original exception if we cannot
+ * determine
+ */
+ private boolean checkCommitSuccessful(String newMetadataLocation,
RuntimeException originalFailure) {
+ try {
+ Table tbl = loadHmsTable();
+ String metadataLocation =
tbl.getParameters().get(METADATA_LOCATION_PROP);
+ return metadataLocation.equals(newMetadataLocation);
Review comment:
@pvary I think I have this case handled now, I wrote a test which
removes the lock the first commit acquires and then places another commit on
top of the first before throwing an exception in the first client's action.
Timeline
Client 1:
Aquire Lock
New Metadata Committed
Lock Released // Simulating the lock being removed or timing out
Client 2:
Aquire Lock
Commit another new metadata
Lock Released
Client 1:
Throws exception in persist method
----------------------------------------------------------------
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]