awslabs/dynamodb-transactions

Working with DynamoDBMapper

nykolaslima opened this issue · 3 comments

In order to use transactions we need to instantiate PutItemRequest and configure all attributes.
Is there any way to use transactions with DynamoDBMapper?

Hi, for my project we also need query and scan. Any specific reason these arent there yet?

Query and scan inside of transactions are very tricky in this model. The transaction library only locks individual items, not ranges of items. Query and Scan can involve an infinite number of items in any range, so unfortunately supporting those would require pretty much a redesign and rewrite of the whole library. However, there are static helper functions in Transaction.java that you can use on any item you get from DynamoDB outside of a transaction to ensure that the items you get back from a scan or a query are valid.

Another approach for Query is to make a table with the same schema as the table you're querying, but without a range key (same hash key, no range key). Your transaction would perform a GetItem on that corresponding dummy item before you perform your query outside of the transaction library. If your transaction doesn't commit, you throw away your query results. This approach locks the entire range for that hash key, so it could result in a bunch of contention depending on your access pattern, but it could work.