Search in sources :

Example 76 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class DynamoAdmin method createMetadataTableIfNotExists.

private void createMetadataTableIfNotExists() throws ExecutionException {
    if (metadataTableExists()) {
        return;
    }
    List<AttributeDefinition> columnsToAttributeDefinitions = new ArrayList<>();
    columnsToAttributeDefinitions.add(AttributeDefinition.builder().attributeName(METADATA_ATTR_TABLE).attributeType(ScalarAttributeType.S).build());
    try {
        client.createTable(CreateTableRequest.builder().attributeDefinitions(columnsToAttributeDefinitions).keySchema(KeySchemaElement.builder().attributeName(METADATA_ATTR_TABLE).keyType(KeyType.HASH).build()).provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(METADATA_TABLE_REQUEST_UNIT).writeCapacityUnits(METADATA_TABLE_REQUEST_UNIT).build()).tableName(getMetadataTable()).build());
    } catch (Exception e) {
        throw new ExecutionException("creating the metadata table failed", e);
    }
    waitForTableCreation(getMetadataTable());
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(software.amazon.awssdk.services.dynamodb.model.AttributeDefinition) ExecutionException(com.scalar.db.exception.storage.ExecutionException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) ObjectNotFoundException(software.amazon.awssdk.services.applicationautoscaling.model.ObjectNotFoundException) ResourceNotFoundException(software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException)

Example 77 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class DeleteStatementHandler method handle.

@Nonnull
@Override
public List<Map<String, AttributeValue>> handle(Operation operation) throws ExecutionException {
    checkArgument(operation, Delete.class);
    Delete delete = (Delete) operation;
    TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
    try {
        delete(delete, tableMetadata);
    } catch (ConditionalCheckFailedException e) {
        throw new NoMutationException("no mutation was applied.", e);
    } catch (TransactionConflictException e) {
        throw new RetriableExecutionException(e.getMessage(), e);
    } catch (DynamoDbException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    return Collections.emptyList();
}
Also used : Delete(com.scalar.db.api.Delete) TableMetadata(com.scalar.db.api.TableMetadata) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) TransactionConflictException(software.amazon.awssdk.services.dynamodb.model.TransactionConflictException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) NoMutationException(com.scalar.db.exception.storage.NoMutationException) Nonnull(javax.annotation.Nonnull)

Example 78 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class SelectStatementHandler method handle.

@Nonnull
@Override
public List<Map<String, AttributeValue>> handle(Operation operation) throws ExecutionException {
    checkArgument(operation, Get.class, Scan.class);
    TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
    try {
        if (ScalarDbUtils.isSecondaryIndexSpecified(operation, tableMetadata)) {
            return executeQueryWithIndex((Selection) operation, tableMetadata);
        }
        if (operation instanceof Get) {
            return executeGet((Get) operation, tableMetadata);
        } else {
            return executeQuery((Scan) operation, tableMetadata);
        }
    } catch (DynamoDbException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Get(com.scalar.db.api.Get) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Nonnull(javax.annotation.Nonnull)

Aggregations

ExecutionException (com.scalar.db.exception.storage.ExecutionException)78 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)23 RetriableExecutionException (com.scalar.db.exception.storage.RetriableExecutionException)18 ObjectNotFoundException (software.amazon.awssdk.services.applicationautoscaling.model.ObjectNotFoundException)18 ResourceNotFoundException (software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException)18 SQLException (java.sql.SQLException)14 ArrayList (java.util.ArrayList)14 Connection (java.sql.Connection)12 Test (org.junit.jupiter.api.Test)11 HashSet (java.util.HashSet)10 NoMutationException (com.scalar.db.exception.storage.NoMutationException)9 TableMetadata (com.scalar.db.api.TableMetadata)8 Value (com.scalar.db.io.Value)8 Put (com.scalar.db.api.Put)7 TransactionState (com.scalar.db.api.TransactionState)6 CrudException (com.scalar.db.exception.transaction.CrudException)6 HashMap (java.util.HashMap)6 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)5 CosmosDatabase (com.azure.cosmos.CosmosDatabase)4 Get (com.scalar.db.api.Get)4