Search in sources :

Example 6 with HoodieLockException

use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.

the class DynamoDBBasedLockProvider method unlock.

@Override
public void unlock() {
    try {
        LOG.info(generateLogStatement(LockState.RELEASING, generateLogSuffixString()));
        if (lock == null) {
            return;
        }
        if (!client.releaseLock(lock)) {
            LOG.warn("The lock has already been stolen");
        }
        lock = null;
        LOG.info(generateLogStatement(LockState.RELEASED, generateLogSuffixString()));
    } catch (Exception e) {
        throw new HoodieLockException(generateLogStatement(LockState.FAILED_TO_RELEASE, generateLogSuffixString()), e);
    }
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) LockNotGrantedException(com.amazonaws.services.dynamodbv2.model.LockNotGrantedException) HoodieLockException(org.apache.hudi.exception.HoodieLockException)

Example 7 with HoodieLockException

use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.

the class DynamoDBBasedLockProvider method createLockTableInDynamoDB.

private void createLockTableInDynamoDB(AmazonDynamoDB dynamoDB, String tableName) {
    String billingMode = lockConfiguration.getConfig().getString(DynamoDbBasedLockConfig.DYNAMODB_LOCK_BILLING_MODE.key());
    KeySchemaElement partitionKeyElement = new KeySchemaElement();
    partitionKeyElement.setAttributeName(DYNAMODB_ATTRIBUTE_NAME);
    partitionKeyElement.setKeyType(KeyType.HASH);
    List<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(partitionKeyElement);
    Collection<AttributeDefinition> attributeDefinitions = new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(DYNAMODB_ATTRIBUTE_NAME).withAttributeType(ScalarAttributeType.S));
    CreateTableRequest createTableRequest = new CreateTableRequest(tableName, keySchema);
    createTableRequest.setAttributeDefinitions(attributeDefinitions);
    createTableRequest.setBillingMode(billingMode);
    if (billingMode.equals(BillingMode.PROVISIONED.name())) {
        createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(Long.parseLong(lockConfiguration.getConfig().getString(DynamoDbBasedLockConfig.DYNAMODB_LOCK_READ_CAPACITY.key()))).withWriteCapacityUnits(Long.parseLong(lockConfiguration.getConfig().getString(DynamoDbBasedLockConfig.DYNAMODB_LOCK_WRITE_CAPACITY.key()))));
    }
    dynamoDB.createTable(createTableRequest);
    LOG.info("Creating dynamoDB table " + tableName + ", waiting for table to be active");
    try {
        TableUtils.waitUntilActive(dynamoDB, tableName, Integer.parseInt(lockConfiguration.getConfig().getString(DynamoDbBasedLockConfig.DYNAMODB_LOCK_TABLE_CREATION_TIMEOUT.key())), 20 * 1000);
    } catch (TableUtils.TableNeverTransitionedToStateException e) {
        throw new HoodieLockException("Created dynamoDB table never transits to active", e);
    } catch (InterruptedException e) {
        throw new HoodieLockException("Thread interrupted while waiting for dynamoDB table to turn active", e);
    }
    LOG.info("Created dynamoDB table " + tableName);
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) ArrayList(java.util.ArrayList) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) TableUtils(com.amazonaws.services.dynamodbv2.util.TableUtils) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 8 with HoodieLockException

use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.

the class DynamoDBBasedLockProvider method tryLock.

@Override
public boolean tryLock(long time, TimeUnit unit) {
    LOG.info(generateLogStatement(LockState.ACQUIRING, generateLogSuffixString()));
    try {
        lock = client.acquireLock(AcquireLockOptions.builder(dynamoDBPartitionKey).withAdditionalTimeToWaitForLock(time).withTimeUnit(TimeUnit.MILLISECONDS).build());
        LOG.info(generateLogStatement(LockState.ACQUIRED, generateLogSuffixString()));
    } catch (InterruptedException e) {
        throw new HoodieLockException(generateLogStatement(LockState.FAILED_TO_ACQUIRE, generateLogSuffixString()), e);
    } catch (LockNotGrantedException e) {
        return false;
    }
    return lock != null && !lock.isExpired();
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) LockNotGrantedException(com.amazonaws.services.dynamodbv2.model.LockNotGrantedException)

Example 9 with HoodieLockException

use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.

the class FileSystemBasedLockProviderTestClass method tryLock.

@Override
public boolean tryLock(long time, TimeUnit unit) {
    try {
        int numRetries = 0;
        synchronized (LOCK) {
            while (fs.exists(this.lockFile)) {
                LOCK.wait(retryWaitTimeMs);
                numRetries++;
                if (numRetries > retryMaxCount) {
                    return false;
                }
            }
            acquireLock();
            return fs.exists(this.lockFile);
        }
    } catch (IOException | InterruptedException e) {
        throw new HoodieLockException("Failed to acquire lock: " + getLock(), e);
    }
}
Also used : HoodieLockException(org.apache.hudi.exception.HoodieLockException) IOException(java.io.IOException) HoodieIOException(org.apache.hudi.exception.HoodieIOException)

Example 10 with HoodieLockException

use of org.apache.hudi.exception.HoodieLockException in project hudi by apache.

the class InProcessLockProvider method tryLock.

@Override
public boolean tryLock(long time, @NotNull TimeUnit unit) {
    LOG.info(getLogMessage(LockState.ACQUIRING));
    if (LOCK.isWriteLockedByCurrentThread()) {
        throw new HoodieLockException(getLogMessage(LockState.ALREADY_ACQUIRED));
    }
    boolean isLockAcquired;
    try {
        isLockAcquired = LOCK.writeLock().tryLock(time, unit);
    } catch (InterruptedException e) {
        throw new HoodieLockException(getLogMessage(LockState.FAILED_TO_ACQUIRE));
    }
    LOG.info(getLogMessage(isLockAcquired ? LockState.ACQUIRED : LockState.FAILED_TO_ACQUIRE));
    return isLockAcquired;
}
Also used : 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