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 循环难道不是一种处理我们超出预置写入单元的情况的方法吗?