private void CallUntilCompletion(BatchWriteItemRequest request, AmazonDynamoDB client) { do { var batchWriteItemResponse = client.BatchWriteItem(request); var result = batchWriteItemResponse.BatchWriteItemResult; request.RequestItems = result.UnprocessedItems; } while (request.RequestItems.Count > 0); }
private void CallUntilCompletion(BatchWriteItemRequest request, Dictionary <string, Dictionary <Key, Document> > documentMap, AmazonDynamoDB client) { do { var batchWriteItemResponse = client.BatchWriteItem(request); var result = batchWriteItemResponse.BatchWriteItemResult; request.RequestItems = result.UnprocessedItems; Dictionary <Key, Document> unprocessedDocuments = new Dictionary <Key, Document>(keyComparer); foreach (var unprocessedItems in result.UnprocessedItems) { string tableName = unprocessedItems.Key; Table table = tableMap[tableName]; Dictionary <Key, Document> tableDocumentMap = documentMap[tableName]; foreach (var writeRequest in unprocessedItems.Value) { if (writeRequest.PutRequest != null) { var key = table.MakeKey(Document.FromAttributeMap(writeRequest.PutRequest.Item)); Document document = null; if (tableDocumentMap.TryGetValue(key, out document)) { // Remove unprocessed requests from the document map // and copy them to unprocessed documents. unprocessedDocuments.Add(key, document); tableDocumentMap.Remove(key); } } } // Commit the remaining documents in the document map foreach (var document in tableDocumentMap.Values) { document.CommitChanges(); } // Replace existing documents with just the unprocessed documents documentMap[tableName] = unprocessedDocuments; } } while (request.RequestItems.Count > 0); // Commit any remaining documents in document map. // This would only happen if we are not able to match the items sent in the request // with the items returned back as unprocessed items. foreach (var tableDocumentMap in documentMap.Values) { foreach (var document in tableDocumentMap.Values) { document.CommitChanges(); } } }