Search in sources :

Example 21 with ExecutionException

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

the class BatchHandler method throwException.

private void throwException(CosmosException exception) throws ExecutionException {
    LOGGER.error(exception.getMessage(), exception);
    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 22 with ExecutionException

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

the class CosmosAdmin method createContainer.

private void createContainer(String database, String table, TableMetadata metadata) throws ExecutionException {
    if (!databaseExists(database)) {
        throw new ExecutionException("the database does not exists");
    }
    CosmosDatabase cosmosDatabase = client.getDatabase(database);
    CosmosContainerProperties properties = computeContainerProperties(table, metadata);
    cosmosDatabase.createContainer(properties);
    CosmosStoredProcedureProperties storedProcedureProperties = computeContainerStoredProcedureProperties();
    cosmosDatabase.getContainer(table).getScripts().createStoredProcedure(storedProcedureProperties);
}
Also used : CosmosDatabase(com.azure.cosmos.CosmosDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) CosmosStoredProcedureProperties(com.azure.cosmos.models.CosmosStoredProcedureProperties) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 23 with ExecutionException

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

the class CosmosAdmin method createTable.

@Override
public void createTable(String namespace, String table, TableMetadata metadata, Map<String, String> options) throws ExecutionException {
    checkMetadata(metadata);
    try {
        createContainer(namespace, table, metadata);
        putTableMetadata(namespace, table, metadata);
    } catch (RuntimeException e) {
        throw new ExecutionException("creating the container failed", e);
    }
}
Also used : ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 24 with ExecutionException

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

the class CosmosAdmin method updateIndexingPolicy.

private void updateIndexingPolicy(String databaseName, String containerName, TableMetadata newTableMetadata) throws ExecutionException {
    CosmosDatabase database = client.getDatabase(databaseName);
    try {
        // get the existing container properties
        CosmosContainerResponse response = database.createContainerIfNotExists(containerName, PARTITION_KEY_PATH);
        CosmosContainerProperties properties = response.getProperties();
        // set the new index policy to the container properties
        properties.setIndexingPolicy(computeIndexingPolicy(newTableMetadata));
        // update the container properties
        database.getContainer(containerName).replace(properties);
    } catch (RuntimeException e) {
        throw new ExecutionException("updating the indexing policy failed", e);
    }
}
Also used : CosmosDatabase(com.azure.cosmos.CosmosDatabase) CosmosContainerProperties(com.azure.cosmos.models.CosmosContainerProperties) ExecutionException(com.scalar.db.exception.storage.ExecutionException) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse)

Example 25 with ExecutionException

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

the class CosmosAdmin method getTableMetadata.

@Override
public TableMetadata getTableMetadata(String namespace, String table) throws ExecutionException {
    try {
        String fullName = getFullTableName(namespace, table);
        CosmosTableMetadata cosmosTableMetadata = readMetadata(fullName);
        if (cosmosTableMetadata == null) {
            return null;
        }
        return convertToTableMetadata(cosmosTableMetadata);
    } catch (RuntimeException e) {
        throw new ExecutionException("getting the container metadata failed", e);
    }
}
Also used : ExecutionException(com.scalar.db.exception.storage.ExecutionException)

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