Skip to content

Commit 7ed8fc7

Browse files
brfrn169josh-wong
andauthored
Use CoreError for messages of RuntimeExceptions in DynamoAdmin (#3007)
Co-authored-by: Josh Wong <[email protected]>
1 parent 2e7cd60 commit 7ed8fc7

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

core/src/main/java/com/scalar/db/common/CoreError.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,30 @@ public enum CoreError implements ScalarDbError {
712712
"Db2 does not support renaming primary key or index key columns",
713713
"",
714714
""),
715+
DYNAMO_IMPORT_NOT_SUPPORTED(
716+
Category.USER_ERROR,
717+
"0223",
718+
"Import-related functionality is not supported in DynamoDB",
719+
"",
720+
""),
721+
DYNAMO_PARTITION_KEY_BLOB_TYPE_NOT_SUPPORTED(
722+
Category.USER_ERROR,
723+
"0224",
724+
"The BLOB type is supported only for the last column in the partition key in DynamoDB. Column: %s",
725+
"",
726+
""),
727+
DYNAMO_CLUSTERING_KEY_BLOB_TYPE_NOT_SUPPORTED(
728+
Category.USER_ERROR,
729+
"0225",
730+
"The BLOB type is not supported for clustering keys in DynamoDB. Column: %s",
731+
"",
732+
""),
733+
DYNAMO_INDEX_COLUMN_BOOLEAN_TYPE_NOT_SUPPORTED(
734+
Category.USER_ERROR,
735+
"0226",
736+
"The BOOLEAN type is not supported for index columns in DynamoDB. Column: %s",
737+
"",
738+
""),
715739

716740
//
717741
// Errors for the concurrency error category

core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -336,24 +336,23 @@ private void checkMetadata(TableMetadata metadata) {
336336
}
337337
if (metadata.getColumnDataType(partitionKeyName) == DataType.BLOB) {
338338
throw new IllegalArgumentException(
339-
"BLOB type is supported only for the last column in partition key in DynamoDB: "
340-
+ partitionKeyName);
339+
CoreError.DYNAMO_PARTITION_KEY_BLOB_TYPE_NOT_SUPPORTED.buildMessage(partitionKeyName));
341340
}
342341
}
343342

344343
for (String clusteringKeyName : metadata.getClusteringKeyNames()) {
345344
if (metadata.getColumnDataType(clusteringKeyName) == DataType.BLOB) {
346345
throw new IllegalArgumentException(
347-
"Currently, BLOB type is not supported for clustering keys in DynamoDB: "
348-
+ clusteringKeyName);
346+
CoreError.DYNAMO_CLUSTERING_KEY_BLOB_TYPE_NOT_SUPPORTED.buildMessage(
347+
clusteringKeyName));
349348
}
350349
}
351350

352351
for (String secondaryIndexName : metadata.getSecondaryIndexNames()) {
353352
if (metadata.getColumnDataType(secondaryIndexName) == DataType.BOOLEAN) {
354353
throw new IllegalArgumentException(
355-
"Currently, BOOLEAN type is not supported for a secondary index in DynamoDB: "
356-
+ secondaryIndexName);
354+
CoreError.DYNAMO_INDEX_COLUMN_BOOLEAN_TYPE_NOT_SUPPORTED.buildMessage(
355+
secondaryIndexName));
357356
}
358357
}
359358
}
@@ -951,16 +950,11 @@ public void createIndex(
951950
throws ExecutionException {
952951
Namespace namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace);
953952
TableMetadata metadata = getTableMetadata(nonPrefixedNamespace, table);
954-
955-
if (metadata == null) {
956-
throw new IllegalArgumentException(
957-
"The " + getFullTableName(namespace, table) + " table does not exist");
958-
}
953+
assert metadata != null;
959954

960955
if (metadata.getColumnDataType(columnName) == DataType.BOOLEAN) {
961956
throw new IllegalArgumentException(
962-
"Currently, BOOLEAN type is not supported for a secondary index in DynamoDB: "
963-
+ columnName);
957+
CoreError.DYNAMO_INDEX_COLUMN_BOOLEAN_TYPE_NOT_SUPPORTED.buildMessage(columnName));
964958
}
965959

966960
long ru = Long.parseLong(options.getOrDefault(REQUEST_UNIT, DEFAULT_REQUEST_UNIT));
@@ -1033,7 +1027,8 @@ columnName, getFullTableName(namespace, table)),
10331027
TableMetadata.newBuilder(tableMetadata).addSecondaryIndex(columnName).build());
10341028
}
10351029

1036-
private boolean rawIndexExists(String nonPrefixedNamespace, String table, String indexName) {
1030+
private boolean rawIndexExists(String nonPrefixedNamespace, String table, String indexName)
1031+
throws ExecutionException {
10371032
Namespace namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace);
10381033
String globalIndexName =
10391034
String.join(
@@ -1061,7 +1056,7 @@ private boolean rawIndexExists(String nonPrefixedNamespace, String table, String
10611056
return true;
10621057
}
10631058
if (retryCount++ >= MAX_RETRY_COUNT) {
1064-
throw new IllegalStateException(
1059+
throw new ExecutionException(
10651060
String.format(
10661061
"Waiting for the secondary index %s on the %s table to be active failed",
10671062
indexName, getFullTableName(namespace, table)));
@@ -1459,15 +1454,13 @@ public void renameColumn(
14591454
@Override
14601455
public TableMetadata getImportTableMetadata(
14611456
String namespace, String table, Map<String, DataType> overrideColumnsType) {
1462-
throw new UnsupportedOperationException(
1463-
"Import-related functionality is not supported in DynamoDB");
1457+
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
14641458
}
14651459

14661460
@Override
14671461
public void addRawColumnToTable(
14681462
String namespace, String table, String columnName, DataType columnType) {
1469-
throw new UnsupportedOperationException(
1470-
"Import-related functionality is not supported in DynamoDB");
1463+
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
14711464
}
14721465

14731466
@Override
@@ -1476,8 +1469,7 @@ public void importTable(
14761469
String table,
14771470
Map<String, String> options,
14781471
Map<String, DataType> overrideColumnsType) {
1479-
throw new UnsupportedOperationException(
1480-
"Import-related functionality is not supported in DynamoDB");
1472+
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
14811473
}
14821474

14831475
@Override

0 commit comments

Comments
 (0)