Search in sources :

Example 66 with ExecutionException

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

the class JdbcTransaction method put.

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

Example 67 with ExecutionException

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

the class CassandraAdmin method createTableInternal.

@VisibleForTesting
void createTableInternal(String keyspace, String table, TableMetadata metadata, Map<String, String> options) throws ExecutionException {
    Create createTable = SchemaBuilder.createTable(quoteIfNecessary(keyspace), quoteIfNecessary(table));
    // Add columns
    for (String pk : metadata.getPartitionKeyNames()) {
        createTable = createTable.addPartitionKey(quoteIfNecessary(pk), toCassandraDataType(metadata.getColumnDataType(pk)));
    }
    for (String ck : metadata.getClusteringKeyNames()) {
        createTable = createTable.addClusteringColumn(quoteIfNecessary(ck), toCassandraDataType(metadata.getColumnDataType(ck)));
    }
    for (String column : metadata.getColumnNames()) {
        if (metadata.getPartitionKeyNames().contains(column) || metadata.getClusteringKeyNames().contains(column)) {
            continue;
        }
        createTable = createTable.addColumn(quoteIfNecessary(column), toCassandraDataType(metadata.getColumnDataType(column)));
    }
    // Add clustering order
    Create.Options createTableWithOptions = createTable.withOptions();
    for (String ck : metadata.getClusteringKeyNames()) {
        Direction direction = metadata.getClusteringOrder(ck) == Order.ASC ? Direction.ASC : Direction.DESC;
        createTableWithOptions = createTableWithOptions.clusteringOrder(quoteIfNecessary(ck), direction);
    }
    // Add compaction strategy
    CompactionStrategy compactionStrategy = CompactionStrategy.valueOf(options.getOrDefault(COMPACTION_STRATEGY, CompactionStrategy.STCS.toString()));
    CompactionOptions<?> strategy;
    switch(compactionStrategy) {
        case LCS:
            strategy = SchemaBuilder.leveledStrategy();
            break;
        case TWCS:
            strategy = SchemaBuilder.timeWindowCompactionStrategy();
            break;
        default:
            strategy = SchemaBuilder.sizedTieredStategy();
    }
    createTableWithOptions = createTableWithOptions.compactionOptions(strategy);
    try {
        clusterManager.getSession().execute(createTableWithOptions.getQueryString());
    } catch (RuntimeException e) {
        throw new ExecutionException(String.format("creating the table %s.%s failed", keyspace, table), e);
    }
}
Also used : Create(com.datastax.driver.core.schemabuilder.Create) ExecutionException(com.scalar.db.exception.storage.ExecutionException) Direction(com.datastax.driver.core.schemabuilder.SchemaBuilder.Direction) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 68 with ExecutionException

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

the class CosmosAdmin method truncateTable.

@Override
public void truncateTable(String namespace, String table) throws ExecutionException {
    try {
        CosmosDatabase database = client.getDatabase(namespace);
        CosmosContainer container = database.getContainer(table);
        CosmosPagedIterable<Record> records = container.queryItems("SELECT t." + ID + ", t." + CONCATENATED_PARTITION_KEY + " FROM " + "t", new CosmosQueryRequestOptions(), Record.class);
        records.forEach(record -> container.deleteItem(record.getId(), new PartitionKey(record.getConcatenatedPartitionKey()), new CosmosItemRequestOptions()));
    } catch (RuntimeException e) {
        throw new ExecutionException("truncating the container failed", e);
    }
}
Also used : CosmosQueryRequestOptions(com.azure.cosmos.models.CosmosQueryRequestOptions) CosmosItemRequestOptions(com.azure.cosmos.models.CosmosItemRequestOptions) CosmosContainer(com.azure.cosmos.CosmosContainer) CosmosDatabase(com.azure.cosmos.CosmosDatabase) PartitionKey(com.azure.cosmos.models.PartitionKey) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 69 with ExecutionException

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

the class CosmosAdmin method dropTable.

@Override
public void dropTable(String namespace, String table) throws ExecutionException {
    if (!databaseExists(namespace)) {
        throw new ExecutionException("the database does not exist");
    }
    CosmosDatabase database = client.getDatabase(namespace);
    if (!containerExists(database, table)) {
        throw new ExecutionException("the container does not exist");
    }
    try {
        database.getContainer(table).delete();
        deleteTableMetadata(namespace, table);
    } catch (RuntimeException e) {
        throw new ExecutionException("deleting the container failed", e);
    }
}
Also used : CosmosDatabase(com.azure.cosmos.CosmosDatabase) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 70 with ExecutionException

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

the class CosmosAdmin method putTableMetadata.

private void putTableMetadata(String namespace, String table, TableMetadata metadata) throws ExecutionException {
    try {
        createMetadataDatabaseAndContainerIfNotExists();
        CosmosTableMetadata cosmosTableMetadata = convertToCosmosTableMetadata(getFullTableName(namespace, table), metadata);
        getMetadataContainer().upsertItem(cosmosTableMetadata);
    } catch (RuntimeException e) {
        throw new ExecutionException("putting the table 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