MakeKey() private method

private MakeKey ( DynamoDBEntry>.IDictionary doc ) : Key
doc DynamoDBEntry>.IDictionary
return Key
        private async Task CallUntilCompletionAsync(BatchWriteItemRequest request, Dictionary <string, Dictionary <Key, Document> > documentMap, IAmazonDynamoDB client, CancellationToken cancellationToken)
#endif
        {
            do
            {
                var result = await client.BatchWriteItemAsync(request, cancellationToken).ConfigureAwait(false);

                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 doc = table.FromAttributeMap(writeRequest.PutRequest.Item);
                            var key = table.MakeKey(doc);

                            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();
                }
            }
        }
Example #2
0
        private void CallUntilCompletion(BatchWriteItemRequest request, 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)
                {
                    Table table = tableMap[unprocessedItems.Key];

                    foreach (var writeRequest in unprocessedItems.Value)
                    {
                        if (writeRequest.PutRequest != null)
                        {
                            var key = table.MakeKey(Document.FromAttributeMap(writeRequest.PutRequest.Item));

                            Document document = null;
                            if (documentMap.TryGetValue(key, out document))
                            {
                                // Remove unprocessed requests from the document map
                                // and copy them to unprocessed documents.
                                unprocessedDocuments.Add(key, document);
                                documentMap.Remove(key);
                            }
                        }
                    }
                }

                // Commit the remaining documents in the document map
                foreach (var document in documentMap.Values)
                {
                    document.CommitChanges();
                }
                documentMap = 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 document in documentMap.Values)
            {
                document.CommitChanges();
            }
        }