Search in sources :

Example 1 with LockProvider

use of org.apache.hudi.common.lock.LockProvider 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)

Aggregations

LockProvider (org.apache.hudi.common.lock.LockProvider)1 HoodieLockException (org.apache.hudi.exception.HoodieLockException)1