pvary commented on code in PR #6451:
URL: https://github.com/apache/iceberg/pull/6451#discussion_r1063368432
##########
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:
If the `tryLock` is failed because of an `InterruptedException` it will
throw a `RuntimeException` and does not set the `lockId`:
```
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.warn("Interrupted while acquiring lock on table {}.{}",
database, tableName, e);
throw new RuntimeException("Interrupted while acquiring
lock", e);
}
```
If the `lockId` is not set then we try to use `findLock` to find the lockId,
and then `doUnlock` to unlock the table.
We need to harden the HMS `lock` request specifically, because it is not
handled by the `RetryingMetastoreClient` because of this annotation:
```
@RetrySemantics.CannotRetry
public LockResponse lock(LockRequest rqst) throws NoSuchTxnException,
TxnAbortedException, MetaException {
```
For more details see:
https://github.com/apache/hive/blob/rel/release-2.3.9/metastore/src/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java#L855-L871
Since both the `unlock`, and the `findLock` is retried, I think we should
not do any extra work there, and expect that the `RetryingMetastoreClient` will
fix our issues when possible
--
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]