|
1 | 1 | package com.scalar.db.storage.dynamo; |
2 | 2 |
|
3 | | -import static com.scalar.db.util.ScalarDbUtils.getFullTableName; |
4 | | - |
5 | 3 | import com.google.common.annotations.VisibleForTesting; |
6 | 4 | import com.google.common.collect.ImmutableMap; |
7 | 5 | import com.google.common.collect.ImmutableSet; |
@@ -1034,26 +1032,44 @@ columnName, getFullTableName(namespace, table)), |
1034 | 1032 | TableMetadata.newBuilder(tableMetadata).addSecondaryIndex(columnName).build()); |
1035 | 1033 | } |
1036 | 1034 |
|
1037 | | - private boolean indexExistsInternal(String nonPrefixedNamespace, String table, String indexName) { |
| 1035 | + private boolean rawIndexExists(String nonPrefixedNamespace, String table, String indexName) { |
1038 | 1036 | Namespace namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace); |
1039 | 1037 | String globalIndexName = |
1040 | 1038 | String.join( |
1041 | 1039 | ".", |
1042 | 1040 | getFullTableName(namespace, table), |
1043 | 1041 | DynamoAdmin.GLOBAL_INDEX_NAME_PREFIX, |
1044 | 1042 | 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) { |
1052 | 1060 | return true; |
1053 | 1061 | } |
| 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); |
1054 | 1069 | } |
| 1070 | + } catch (ResourceNotFoundException e) { |
| 1071 | + return false; |
1055 | 1072 | } |
1056 | | - return false; |
1057 | 1073 | } |
1058 | 1074 |
|
1059 | 1075 | private void waitForIndexCreation(Namespace namespace, String table, String columnName) |
@@ -1391,7 +1407,7 @@ public void repairTable( |
1391 | 1407 | try { |
1392 | 1408 | createTableInternal(nonPrefixedNamespace, table, metadata, true, options); |
1393 | 1409 | for (String indexColumnName : metadata.getSecondaryIndexNames()) { |
1394 | | - if (!indexExistsInternal(nonPrefixedNamespace, table, indexColumnName)) { |
| 1410 | + if (!rawIndexExists(nonPrefixedNamespace, table, indexColumnName)) { |
1395 | 1411 | createIndex(nonPrefixedNamespace, table, indexColumnName, options); |
1396 | 1412 | } |
1397 | 1413 | } |
|
0 commit comments