Search in sources :

Example 46 with ExecutionException

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

the class DynamoAdmin method waitForTableDeletion.

private void waitForTableDeletion(String namespace, String tableName) throws ExecutionException {
    try {
        while (true) {
            Uninterruptibles.sleepUninterruptibly(WAITING_DURATION_SECS, TimeUnit.SECONDS);
            Set<String> tableSet = getNamespaceTableNames(namespace);
            if (!tableSet.contains(tableName)) {
                break;
            }
        }
    } catch (Exception e) {
        throw new ExecutionException("waiting for the table deletion failed", e);
    }
}
Also used : 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 47 with ExecutionException

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

the class DynamoAdmin method waitForIndexCreation.

private void waitForIndexCreation(String namespace, String table, String columnName) throws ExecutionException {
    try {
        String indexName = getGlobalIndexName(namespace, table, columnName);
        while (true) {
            Uninterruptibles.sleepUninterruptibly(WAITING_DURATION_SECS, TimeUnit.SECONDS);
            DescribeTableResponse response = client.describeTable(DescribeTableRequest.builder().tableName(getFullTableName(namespace, table)).build());
            for (GlobalSecondaryIndexDescription globalSecondaryIndex : response.table().globalSecondaryIndexes()) {
                if (globalSecondaryIndex.indexName().equals(indexName)) {
                    if (globalSecondaryIndex.indexStatus() == IndexStatus.ACTIVE) {
                        return;
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new ExecutionException("waiting for the secondary index creation failed", e);
    }
}
Also used : DescribeTableResponse(software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse) GlobalSecondaryIndexDescription(software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexDescription) 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 48 with ExecutionException

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

the class DynamoAdmin method waitForTableBackupEnabledAtCreation.

private void waitForTableBackupEnabledAtCreation(String namespace, String table) throws ExecutionException {
    try {
        while (true) {
            Uninterruptibles.sleepUninterruptibly(WAITING_DURATION_SECS, TimeUnit.SECONDS);
            DescribeContinuousBackupsResponse describeContinuousBackupsResponse = client.describeContinuousBackups(DescribeContinuousBackupsRequest.builder().tableName(getFullTableName(namespace, table)).build());
            if (describeContinuousBackupsResponse.continuousBackupsDescription().continuousBackupsStatus() == ContinuousBackupsStatus.ENABLED) {
                break;
            }
        }
    } catch (Exception e) {
        throw new ExecutionException("waiting for the table backup enabled at creation failed", e);
    }
}
Also used : DescribeContinuousBackupsResponse(software.amazon.awssdk.services.dynamodb.model.DescribeContinuousBackupsResponse) 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 49 with ExecutionException

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

the class DynamoAdmin method dropTable.

@Override
public void dropTable(String namespace, String table) throws ExecutionException {
    disableAutoScaling(namespace, table);
    String fullTableName = getFullTableName(namespace, table);
    try {
        client.deleteTable(DeleteTableRequest.builder().tableName(fullTableName).build());
    } catch (Exception e) {
        throw new ExecutionException("deleting table " + fullTableName + " failed", e);
    }
    waitForTableDeletion(namespace, table);
    deleteTableMetadata(namespace, table);
}
Also used : 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 50 with ExecutionException

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

the class DynamoAdmin method readMetadata.

private TableMetadata readMetadata(String fullName) throws ExecutionException {
    Map<String, AttributeValue> key = new HashMap<>();
    key.put(METADATA_ATTR_TABLE, AttributeValue.builder().s(fullName).build());
    try {
        Map<String, AttributeValue> metadata = client.getItem(GetItemRequest.builder().tableName(getFullTableName(metadataNamespace, METADATA_TABLE)).key(key).consistentRead(true).build()).item();
        if (metadata.isEmpty()) {
            // The specified table is not found
            return null;
        }
        return createTableMetadata(metadata);
    } catch (Exception e) {
        throw new ExecutionException("Failed to read the table metadata", e);
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) HashMap(java.util.HashMap) 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)

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