Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ private void acquireLockInternal(long time, TimeUnit unit, LockComponent lockCom
throw e;
}
}
} finally {
// it is better to release WAITING lock, otherwise hive lock will hang forever
if (this.lock != null && this.lock.getState() != LockState.ACQUIRED) {
hiveClient.unlock(this.lock.getLockid());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this hiveClient.unlock(id) throw an exception that the lock is not acquired ? In the test case below, are you generating this scenario where the LOCK is in WAITING stage and you try to release it

}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,35 @@ public void testReentrantLock() throws Exception {
lockProvider.unlock();
}

@Test
public void testWaitingLock() throws Exception {
// create different HiveMetastoreBasedLockProvider to simulate different applications
HiveMetastoreBasedLockProvider lockProvider1 = new HiveMetastoreBasedLockProvider(lockConfiguration, hiveConf());
HiveMetastoreBasedLockProvider lockProvider2 = new HiveMetastoreBasedLockProvider(lockConfiguration, hiveConf());
lockComponent.setOperationType(DataOperationType.NO_TXN);
Assertions.assertTrue(lockProvider1.acquireLock(lockConfiguration.getConfig()
.getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP), TimeUnit.MILLISECONDS, lockComponent));
try {
boolean acquireStatus = lockProvider2.acquireLock(lockConfiguration.getConfig()
.getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP), TimeUnit.MILLISECONDS, lockComponent);
Assertions.assertFalse(acquireStatus);
} catch (IllegalArgumentException e) {
// expected
}
lockProvider1.unlock();
// create the third HiveMetastoreBasedLockProvider to acquire lock
HiveMetastoreBasedLockProvider lockProvider3 = new HiveMetastoreBasedLockProvider(lockConfiguration, hiveConf());
boolean acquireStatus = lockProvider3.acquireLock(lockConfiguration.getConfig()
.getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP), TimeUnit.MILLISECONDS, lockComponent);
// we should acquired lock, since lockProvider1 has already released lock
Assertions.assertTrue(acquireStatus);
lockProvider3.unlock();
// close all HiveMetastoreBasedLockProvider
lockProvider1.close();
lockProvider2.close();
lockProvider3.close();
}

@Test
public void testUnlockWithoutLock() {
HiveMetastoreBasedLockProvider lockProvider = new HiveMetastoreBasedLockProvider(lockConfiguration, hiveConf());
Expand Down