pvary commented on code in PR #6451:
URL: https://github.com/apache/iceberg/pull/6451#discussion_r1062153218
##########
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)) {
+ // No lock found
+ LOG.info("No lock found with {} agentInfo", agentInfo);
+ return;
+ }
+
+ id = foundLockId.get();
+ } else {
+ LOG.warn("Could not find lock with HMSClient {}",
MetastoreClientVersion.current());
+ return;
+ }
+ } else {
+ id = lockId.get();
+ }
+
+ doUnlock(id);
+ } catch (InterruptedException ie) {
+ if (id != null) {
Review Comment:
TBH this was the original change which started my thinking and exploded into
a general hardening 😄
In Flink we had the following situation:
- Commited a change and tried to unlock the table
- The first unlock failed because of a network issue
- RetryingMetastoreClient started the sleep between retries
- The job was interrupted
- The lock was not removed
So this change aims to try to unlock the table in any case, especially in
the situation when there is an interrupt.
--
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]