Search in sources :

Example 36 with ExecutionException

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

the class MutateStatementHandler method throwException.

private void throwException(CosmosException exception) throws ExecutionException {
    LOGGER.error(exception.getMessage());
    int statusCode = exception.getSubStatusCode();
    if (statusCode == CosmosErrorCode.PRECONDITION_FAILED.get()) {
        throw new NoMutationException("no mutation was applied.");
    } else if (statusCode == CosmosErrorCode.RETRY_WITH.get()) {
        throw new RetriableExecutionException(exception.getMessage(), exception);
    }
    throw new ExecutionException(exception.getMessage(), exception);
}
Also used : RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) NoMutationException(com.scalar.db.exception.storage.NoMutationException)

Example 37 with ExecutionException

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

the class JdbcTransaction method delete.

@Override
public void delete(Delete delete) throws CrudException {
    delete = copyAndSetTargetToIfNot(delete);
    // Ignore the condition in the delete
    if (delete.getCondition().isPresent()) {
        LOGGER.warn("ignoring the condition of the mutation: {}", delete);
        delete.withCondition(null);
    }
    try {
        jdbcService.delete(delete, connection);
    } catch (SQLException e) {
        throw createCrudException(e, "delete operation failed");
    } catch (ExecutionException e) {
        throw new CrudException("delete operation failed", e);
    }
}
Also used : SQLException(java.sql.SQLException) ExecutionException(com.scalar.db.exception.storage.ExecutionException) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 38 with ExecutionException

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

the class GrpcScanOnBidirectionalStream method closeScanner.

public void closeScanner() throws ExecutionException {
    try {
        if (!hasMoreResults.get()) {
            return;
        }
        hasMoreResults.set(false);
        requestStream.onCompleted();
    } catch (StatusRuntimeException e) {
        throw new ExecutionException("failed to close the scanner", e);
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 39 with ExecutionException

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

the class CrudHandler method getFromStorage.

private Optional<TransactionResult> getFromStorage(Get get) throws CrudException {
    try {
        // get only after image columns
        get.clearProjections();
        LinkedHashSet<String> afterImageColumnNames = tableMetadataManager.getTransactionalTableMetadata(get).getAfterImageColumnNames();
        get.withProjections(afterImageColumnNames);
        get.withConsistency(Consistency.LINEARIZABLE);
        return storage.get(get).map(TransactionResult::new);
    } catch (ExecutionException e) {
        throw new CrudException("get failed.", e);
    }
}
Also used : ExecutionException(com.scalar.db.exception.storage.ExecutionException) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 40 with ExecutionException

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

the class DynamoAdmin method createTable.

@Override
public void createTable(String namespace, String table, TableMetadata metadata, Map<String, String> options) throws ExecutionException {
    checkMetadata(metadata);
    long ru = Long.parseLong(options.getOrDefault(REQUEST_UNIT, DEFAULT_REQUEST_UNIT));
    CreateTableRequest.Builder requestBuilder = CreateTableRequest.builder();
    buildAttributeDefinitions(requestBuilder, metadata);
    buildPrimaryKey(requestBuilder, metadata);
    buildSecondaryIndexes(namespace, table, requestBuilder, metadata, ru);
    requestBuilder.provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(ru).writeCapacityUnits(ru).build());
    requestBuilder.tableName(getFullTableName(namespace, table));
    try {
        client.createTable(requestBuilder.build());
    } catch (Exception e) {
        throw new ExecutionException("creating the table failed", e);
    }
    waitForTableCreation(namespace, table);
    boolean noScaling = Boolean.parseBoolean(options.getOrDefault(NO_SCALING, DEFAULT_NO_SCALING));
    if (!noScaling) {
        enableAutoScaling(namespace, table, metadata.getSecondaryIndexNames(), ru);
    }
    boolean noBackup = Boolean.parseBoolean(options.getOrDefault(NO_BACKUP, DEFAULT_NO_BACKUP));
    if (!noBackup) {
        enableContinuousBackup(namespace, table);
    }
    createMetadataTableIfNotExists(noBackup);
    putTableMetadata(namespace, table, metadata);
}
Also used : ExecutionException(com.scalar.db.exception.storage.ExecutionException) CreateTableRequest(software.amazon.awssdk.services.dynamodb.model.CreateTableRequest) 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)

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