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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
Aggregations