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);
}
}
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);
}
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();
}
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);
}
}
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;
}
Aggregations