Skip to content

Commit 3700df9

Browse files
committed
Apply suggestions
1 parent 82354b9 commit 3700df9

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.scalar.db.storage.dynamo;
22

3-
import static com.scalar.db.util.ScalarDbUtils.getFullTableName;
4-
53
import com.google.common.annotations.VisibleForTesting;
64
import com.google.common.collect.ImmutableMap;
75
import com.google.common.collect.ImmutableSet;
@@ -1034,26 +1032,44 @@ columnName, getFullTableName(namespace, table)),
10341032
TableMetadata.newBuilder(tableMetadata).addSecondaryIndex(columnName).build());
10351033
}
10361034

1037-
private boolean indexExistsInternal(String nonPrefixedNamespace, String table, String indexName) {
1035+
private boolean rawIndexExists(String nonPrefixedNamespace, String table, String indexName) {
10381036
Namespace namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace);
10391037
String globalIndexName =
10401038
String.join(
10411039
".",
10421040
getFullTableName(namespace, table),
10431041
DynamoAdmin.GLOBAL_INDEX_NAME_PREFIX,
10441042
indexName);
1045-
DescribeTableResponse response =
1046-
client.describeTable(
1047-
DescribeTableRequest.builder().tableName(getFullTableName(namespace, table)).build());
1048-
for (GlobalSecondaryIndexDescription globalSecondaryIndex :
1049-
response.table().globalSecondaryIndexes()) {
1050-
if (globalSecondaryIndex.indexName().equals(globalIndexName)) {
1051-
if (globalSecondaryIndex.indexStatus() == IndexStatus.ACTIVE) {
1043+
int retryCount = 0;
1044+
try {
1045+
while (true) {
1046+
DescribeTableResponse response =
1047+
client.describeTable(
1048+
DescribeTableRequest.builder()
1049+
.tableName(getFullTableName(namespace, table))
1050+
.build());
1051+
GlobalSecondaryIndexDescription description =
1052+
response.table().globalSecondaryIndexes().stream()
1053+
.filter(d -> d.indexName().equals(globalIndexName))
1054+
.findFirst()
1055+
.orElse(null);
1056+
if (description == null) {
1057+
return false;
1058+
}
1059+
if (description.indexStatus() == IndexStatus.ACTIVE) {
10521060
return true;
10531061
}
1062+
if (retryCount++ >= MAX_RETRY_COUNT) {
1063+
throw new IllegalStateException(
1064+
String.format(
1065+
"Waiting for the secondary index %s on the %s table to be active failed",
1066+
indexName, getFullTableName(namespace, table)));
1067+
}
1068+
Uninterruptibles.sleepUninterruptibly(waitingDurationSecs, TimeUnit.SECONDS);
10541069
}
1070+
} catch (ResourceNotFoundException e) {
1071+
return false;
10551072
}
1056-
return false;
10571073
}
10581074

10591075
private void waitForIndexCreation(Namespace namespace, String table, String columnName)
@@ -1391,7 +1407,7 @@ public void repairTable(
13911407
try {
13921408
createTableInternal(nonPrefixedNamespace, table, metadata, true, options);
13931409
for (String indexColumnName : metadata.getSecondaryIndexNames()) {
1394-
if (!indexExistsInternal(nonPrefixedNamespace, table, indexColumnName)) {
1410+
if (!rawIndexExists(nonPrefixedNamespace, table, indexColumnName)) {
13951411
createIndex(nonPrefixedNamespace, table, indexColumnName, options);
13961412
}
13971413
}

0 commit comments

Comments
 (0)