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)
.
.
.
The above exception was caught when attempting to run the following code sample.
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);
I have 1 table set up with 8 Write Units configured.
In my BatchWriteItemRequest I have 9 PutRequestItems.
When the first time in the while loop, 8 out of the 9 PutRequestItems were processed.
Therefore, the loop was entered again, trying to process the one remaining request.
However, the code would hang at
result = client.batchWriteItem(batchWriteItemRequest); for around 149 seconds. After then, the above mentioned exception is thrown.
It seems the only way to bypass this was to set a higher Write Provisioning Unit. However, isn’t the while-do loop a way to handle cases where we exceed our provisioned Write Units?
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:
see http://aws.amazon.com/releasenotes/Java/5659251433242996