Search in sources :

Example 41 with ExecutionException

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

the class DynamoAdmin method waitForIndexDeletion.

private void waitForIndexDeletion(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());
            boolean deleted = true;
            for (GlobalSecondaryIndexDescription globalSecondaryIndex : response.table().globalSecondaryIndexes()) {
                if (globalSecondaryIndex.indexName().equals(indexName)) {
                    deleted = false;
                    break;
                }
            }
            if (deleted) {
                break;
            }
        }
    } catch (Exception e) {
        throw new ExecutionException("waiting for the secondary index deletion 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 42 with ExecutionException

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

the class DynamoAdmin method deleteTableMetadata.

private void deleteTableMetadata(String namespace, String table) throws ExecutionException {
    String metadataTable = getFullTableName(metadataNamespace, METADATA_TABLE);
    Map<String, AttributeValue> keyToDelete = new HashMap<>();
    keyToDelete.put(METADATA_ATTR_TABLE, AttributeValue.builder().s(getFullTableName(namespace, table)).build());
    try {
        client.deleteItem(DeleteItemRequest.builder().tableName(metadataTable).key(keyToDelete).build());
    } catch (Exception e) {
        throw new ExecutionException("deleting the metadata failed", e);
    }
    ScanResponse scanResponse;
    try {
        scanResponse = client.scan(ScanRequest.builder().tableName(metadataTable).limit(1).build());
    } catch (Exception e) {
        throw new ExecutionException("scanning the metadata table failed", e);
    }
    if (scanResponse.count() == 0) {
        try {
            client.deleteTable(DeleteTableRequest.builder().tableName(metadataTable).build());
        } catch (Exception e) {
            throw new ExecutionException("deleting the empty metadata table failed", e);
        }
        waitForTableDeletion(metadataNamespace, METADATA_TABLE);
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) HashMap(java.util.HashMap) ScanResponse(software.amazon.awssdk.services.dynamodb.model.ScanResponse) 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 43 with ExecutionException

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

the class DynamoAdmin method getNamespaceTableNames.

@Override
public Set<String> getNamespaceTableNames(String namespace) throws ExecutionException {
    try {
        Set<String> tableSet = new HashSet<>();
        String lastEvaluatedTableName = null;
        do {
            ListTablesRequest listTablesRequest = ListTablesRequest.builder().exclusiveStartTableName(lastEvaluatedTableName).build();
            ListTablesResponse listTablesResponse = client.listTables(listTablesRequest);
            lastEvaluatedTableName = listTablesResponse.lastEvaluatedTableName();
            List<String> tableNames = listTablesResponse.tableNames();
            String prefix = namespace + ".";
            for (String tableName : tableNames) {
                if (tableName.startsWith(prefix)) {
                    tableSet.add(tableName.substring(prefix.length()));
                }
            }
        } while (lastEvaluatedTableName != null);
        return tableSet;
    } catch (Exception e) {
        throw new ExecutionException("getting list of tables failed", e);
    }
}
Also used : ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse) 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) HashSet(java.util.HashSet)

Example 44 with ExecutionException

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

the class DynamoAdmin method waitForTableCreation.

private void waitForTableCreation(String namespace, String table) throws ExecutionException {
    try {
        while (true) {
            Uninterruptibles.sleepUninterruptibly(WAITING_DURATION_SECS, TimeUnit.SECONDS);
            DescribeTableResponse describeTableResponse = client.describeTable(DescribeTableRequest.builder().tableName(getFullTableName(namespace, table)).build());
            if (describeTableResponse.table().tableStatus() == TableStatus.ACTIVE) {
                break;
            }
        }
    } catch (Exception e) {
        throw new ExecutionException("waiting for the table creation failed", e);
    }
}
Also used : DescribeTableResponse(software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse) 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 45 with ExecutionException

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

the class DynamoAdmin method dropIndex.

@Override
public void dropIndex(String namespace, String table, String columnName) throws ExecutionException {
    try {
        client.updateTable(UpdateTableRequest.builder().tableName(getFullTableName(namespace, table)).globalSecondaryIndexUpdates(GlobalSecondaryIndexUpdate.builder().delete(DeleteGlobalSecondaryIndexAction.builder().indexName(getGlobalIndexName(namespace, table, columnName)).build()).build()).build());
    } catch (Exception e) {
        throw new ExecutionException("dropping the secondary index failed", e);
    }
    waitForIndexDeletion(namespace, table, columnName);
    // disable auto scaling
    List<DeleteScalingPolicyRequest> deleteScalingPolicyRequestList = new ArrayList<>();
    List<DeregisterScalableTargetRequest> deregisterScalableTargetRequestList = new ArrayList<>();
    for (String scalingType : SECONDARY_INDEX_SCALING_TYPE_SET) {
        deleteScalingPolicyRequestList.add(buildDeleteScalingPolicyRequest(getGlobalIndexResourceID(namespace, table, columnName), scalingType));
        deregisterScalableTargetRequestList.add(buildDeregisterScalableTargetRequest(getGlobalIndexResourceID(namespace, table, columnName), scalingType));
    }
    deleteScalingPolicy(deleteScalingPolicyRequestList);
    deregisterScalableTarget(deregisterScalableTargetRequestList);
    // update metadata
    TableMetadata tableMetadata = getTableMetadata(namespace, table);
    putTableMetadata(namespace, table, TableMetadata.newBuilder(tableMetadata).removeSecondaryIndex(columnName).build());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) DeregisterScalableTargetRequest(software.amazon.awssdk.services.applicationautoscaling.model.DeregisterScalableTargetRequest) ArrayList(java.util.ArrayList) DeleteScalingPolicyRequest(software.amazon.awssdk.services.applicationautoscaling.model.DeleteScalingPolicyRequest) 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