等待从DB中删除DynamoDB表

时间:2013-07-19 17:32:57

标签: amazon-dynamodb

我在DynamoDB documentation中找到了关于同步删除给定表的示例。

在调用此方法之前,我们发送了使用类DeleteTableRequest删除表的请求。

private static void waitForTableToBeDeleted(String tableName) {
        System.out.println("Waiting for " + tableName + " while status DELETING...");

        long startTime = System.currentTimeMillis();
        long endTime = startTime + (10 * 60 * 1000);
        while (System.currentTimeMillis() < endTime) {
            try {
                DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
                TableDescription tableDescription = client.describeTable(request).getTable();
                String tableStatus = tableDescription.getTableStatus();
                System.out.println("  - current state: " + tableStatus);
                if (tableStatus.equals(TableStatus.ACTIVE.toString())) return;
            } catch (ResourceNotFoundException e) {
                System.out.println("Table " + tableName + " is not found. It was deleted.");
                return;
            }
            try {Thread.sleep(1000 * 20);} catch (Exception e) {}
        }
        throw new RuntimeException("Table " + tableName + " was never deleted");
    }

我的问题是,他们如何在最新的例子中使用ResourceNotFoundException时他们在documentation中提到的被弃用了?我们应该用什么呢?

1 个答案:

答案 0 :(得分:2)

您指向的文档链接是针对Amazon DynamoDB API的V1,已弃用。引入本地二级索引的V2版本包含在com.amazonaws.services.dynamodbv2包中。以下是ResourceNotFoundException的V2 documentation