2
com.amazonaws.AmazonClientException: Unable to execute HTTP request: Connection reset
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:324)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:164)
    at com.amazonaws.services.dynamodb.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:985)
    at com.amazonaws.services.dynamodb.AmazonDynamoDBClient.batchWriteItem(AmazonDynamoDBClient.java:365)
    .
    .
    .

尝试运行以下代码示例时捕获了上述异常。

BatchWriteItemResult result;
BatchWriteItemRequest batchWriteItemRequest = new BatchWriteItemRequest();
do {
    System.out.println("Making the request.");                         
    batchWriteItemRequest.withRequestItems(requestItems);
    result = client.batchWriteItem(batchWriteItemRequest);

    // Print consumed capacity units
    for(Map.Entry<String, BatchWriteResponse> entry : result.getResponses().entrySet()) {
        String tableName = entry.getKey();
        Double consumedCapacityUnits = entry.getValue().getConsumedCapacityUnits();
        System.out.println("Consumed capacity units for table " + tableName + ": " + consumedCapacityUnits);
     }

  // Check for unprocessed keys which could happen if you exceed provisioned throughput
    System.out.println("Unprocessed Put and Delete requests: \n" + result.getUnprocessedItems());
    requestItems = result.getUnprocessedItems();
} while (result.getUnprocessedItems().size() > 0);

我设置了 1 个表,配置了 8 个写入单元。

在我的BatchWriteItemRequest我有 9 PutRequestItems

当第一次在 while 循环中时,处理了 9 个 PutRequestItems 中的 8 个。因此,再次进入循环,试图处理剩下的一个请求。

但是,代码会挂起 result = client.batchWriteItem(batchWriteItemRequest);大约 149 秒。之后,抛出上述异常。

绕过这一点的唯一方法似乎是设置更高的写入配置单元。但是,while-do 循环难道不是一种处理我们超出预置写入单元的情况的方法吗?

4

2 回答 2

0

There was one release of the AWS SDK for Java which broke retry behavior in the way you're describing. Basically, the input stream for the request wasn't getting reset between attempts, so each retry would immediately fail. DynamoDB does 10 retries with exponential backoff by default, resulting in the very long delays that you saw. Update your SDK to get around this issue:

http://aws.amazon.com/sdkforjava/

于 2012-12-06T19:09:59.250 回答
0

It seems to be a bug on the Java Driver v. 1.3.21 (or maybe including older versions).

1.3.21.1 was released just to take care of that:

Resolved Issues

SocketException During Request Retries

Fixes an issue where retries caused by service error responses (i.e. not IO error retries) aren't able to correctly resend the request payload for services like Amazon DynamoDB that utilize request payloads.

see http://aws.amazon.com/releasenotes/Java/5659251433242996

于 2012-12-10T23:04:01.680 回答