use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.
the class TestZookeeperBasedLockProvider method testReentrantLock.
@Test
public void testReentrantLock() {
ZookeeperBasedLockProvider zookeeperBasedLockProvider = new ZookeeperBasedLockProvider(lockConfiguration, client);
Assertions.assertTrue(zookeeperBasedLockProvider.tryLock(lockConfiguration.getConfig().getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
try {
zookeeperBasedLockProvider.tryLock(lockConfiguration.getConfig().getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS);
Assertions.fail();
} catch (HoodieLockException e) {
// expected
}
zookeeperBasedLockProvider.unlock();
}
use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.
the class InProcessLockProvider method unlock.
@Override
public void unlock() {
LOG.info(getLogMessage(LockState.RELEASING));
try {
if (LOCK.isWriteLockedByCurrentThread()) {
LOCK.writeLock().unlock();
} else {
LOG.warn("Cannot unlock because the current thread does not hold the lock.");
}
} catch (Exception e) {
throw new HoodieLockException(getLogMessage(LockState.FAILED_TO_RELEASE), e);
}
LOG.info(getLogMessage(LockState.RELEASED));
}
use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.
the class LockManager method lock.
public void lock() {
if (writeConfig.getWriteConcurrencyMode().supportsOptimisticConcurrencyControl()) {
LockProvider lockProvider = getLockProvider();
int retryCount = 0;
boolean acquired = false;
while (retryCount <= maxRetries) {
try {
acquired = lockProvider.tryLock(writeConfig.getLockAcquireWaitTimeoutInMs(), TimeUnit.MILLISECONDS);
if (acquired) {
break;
}
LOG.info("Retrying to acquire lock...");
Thread.sleep(maxWaitTimeInMs);
retryCount++;
} catch (HoodieLockException | InterruptedException e) {
if (retryCount >= maxRetries) {
throw new HoodieLockException("Unable to acquire lock, lock object ", e);
}
}
}
if (!acquired) {
throw new HoodieLockException("Unable to acquire lock, lock object " + lockProvider.getLock());
}
}
}
use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.
the class ZookeeperBasedLockProvider method acquireLock.
private void acquireLock(long time, TimeUnit unit) throws Exception {
ValidationUtils.checkArgument(this.lock == null, generateLogStatement(LockState.ALREADY_ACQUIRED, generateLogSuffixString()));
InterProcessMutex newLock = new InterProcessMutex(this.curatorFrameworkClient, lockConfiguration.getConfig().getString(ZK_BASE_PATH_PROP_KEY) + "/" + this.lockConfiguration.getConfig().getString(ZK_LOCK_KEY_PROP_KEY));
boolean acquired = newLock.acquire(time, unit);
if (!acquired) {
throw new HoodieLockException(generateLogStatement(LockState.FAILED_TO_ACQUIRE, generateLogSuffixString()));
}
if (newLock.isAcquiredInThisProcess()) {
lock = newLock;
} else {
throw new HoodieLockException(generateLogStatement(LockState.FAILED_TO_ACQUIRE, generateLogSuffixString()));
}
}
use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.
the class ZookeeperBasedLockProvider method tryLock.
@Override
public boolean tryLock(long time, TimeUnit unit) {
LOG.info(generateLogStatement(LockState.ACQUIRING, generateLogSuffixString()));
try {
acquireLock(time, unit);
LOG.info(generateLogStatement(LockState.ACQUIRED, generateLogSuffixString()));
} catch (HoodieLockException e) {
throw e;
} catch (Exception e) {
throw new HoodieLockException(generateLogStatement(LockState.FAILED_TO_ACQUIRE, generateLogSuffixString()), e);
}
return lock != null && lock.isAcquiredInThisProcess();
}
Aggregations