Search in sources :

Example 1 with HoodieLockException

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();
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) ZookeeperBasedLockProvider(org.apache.hudi.client.transaction.lock.ZookeeperBasedLockProvider) Test(org.junit.jupiter.api.Test)

Example 2 with HoodieLockException

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));
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) HoodieLockException(org.apache.hudi.exception.HoodieLockException)

Example 3 with HoodieLockException

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());
        }
    }
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) LockProvider(org.apache.hudi.common.lock.LockProvider)

Example 4 with HoodieLockException

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()));
    }
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) InterProcessMutex(org.apache.curator.framework.recipes.locks.InterProcessMutex)

Example 5 with HoodieLockException

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();
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) HoodieLockException(org.apache.hudi.exception.HoodieLockException)

Aggregations

HoodieLockException (org.apache.hudi.exception.HoodieLockException)12 LockNotGrantedException (com.amazonaws.services.dynamodbv2.model.LockNotGrantedException)2 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 TableUtils (com.amazonaws.services.dynamodbv2.util.TableUtils)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InterProcessMutex (org.apache.curator.framework.recipes.locks.InterProcessMutex)1 LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)1 ZookeeperBasedLockProvider (org.apache.hudi.client.transaction.lock.ZookeeperBasedLockProvider)1 LockProvider (org.apache.hudi.common.lock.LockProvider)1 HoodieIOException (org.apache.hudi.exception.HoodieIOException)1 TException (org.apache.thrift.TException)1 Test (org.junit.jupiter.api.Test)1