0

我是 DynamoDB 的新手,我在 JVM 中有一个本地实例正在运行,但是当我尝试创建一个定义为

GlobalSecondaryIndexUpdate stockIndex = new GlobalSecondaryIndexUpdate()
        .withCreate(new CreateGlobalSecondaryIndexAction()
                .withIndexName("StockIndex")
                .withKeySchema(new KeySchemaElement().withAttributeName("stock").withKeyType(KeyType.RANGE), // Partition key
                        new KeySchemaElement().withAttributeName("date").withKeyType(KeyType.RANGE)) // Compound key?
                .withProjection(new Projection().withProjectionType(projectionType)));

我得到一个未知的内部故障,例如:

Caused by: com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: The request processing has failed because of an unknown error, exception or failure. (Service: AmazonDynamoDBv2; Status Code: 500; Error Code: InternalFailure; Request ID: dccfbf27-2e33-463c-b36e-97a432f4cd6b)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1588)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1258)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:742)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:2089)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2065)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeUpdateTable(AmazonDynamoDBClient.java:1921)

尝试创建 GSI 时。我定义的索引是错误的,还是 DynamoDB Local 不支持?

2018 年 7 月 30 日更新:

我测试使用:

// StockIndex
GlobalSecondaryIndexUpdate stockIndex = new GlobalSecondaryIndexUpdate()
        .withCreate(new CreateGlobalSecondaryIndexAction()
                .withIndexName("StockIndex")
                .withKeySchema(
                        new KeySchemaElement().withAttributeName("stock").withKeyType(KeyType.HASH)) // Partition key
                        new KeySchemaElement().withAttributeName("date").withKeyType(KeyType.RANGE)) // Compound key?
                .withProjection(new Projection().withProjectionType(ProjectionType.ALL)));

以及没有 RANGE 键date,但两次我都得到了同样的模糊 InternalFailure。我怀疑 DynamoDB 本地实例根本不支持 GSI(尽管使用说明中根本没有提到二级索引)

4

2 回答 2

1

有可能的。我猜你得到的错误是因为你有

.withKeyType(KeyType.RANGE)

指定两次。只有一个属性可以是范围/排序键,另一个需要是哈希键。

于 2018-07-26T01:26:53.333 回答
0

事实证明存在两个问题:(1) 缺少 HASH/分区键和 (2) 我没有指定明确的“预置吞吐量”。以下代码有效:

CreateGlobalSecondaryIndexAction stockIndex = new CreateGlobalSecondaryIndexAction()
            .withIndexName("StockIndex")
            .withKeySchema(
                    new KeySchemaElement().withAttributeName("stock").withKeyType(KeyType.HASH), // Partition key
                    new KeySchemaElement().withAttributeName("date").withKeyType(KeyType.RANGE)) // Sort key             
            .withProvisionedThroughput(new ProvisionedThroughput(20L, 20L))
            .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

注意withProvisionedThroughput通话。

于 2018-07-30T12:46:34.333 回答