Are there any issues with single-items conditional writes?
kappolo opened this issue · 3 comments
Hello,
I know this may sound as a silly question, but does your library support conditional writes on single objects, provided that those writes are included in a transaction?
Since you are storing temporary images of the objects not yet committed in a temporary table, I was wondering how this will affect the case of conditional writes.
What if within the same transaction a conditional write fails, I therefore retrieve the current state of the object and I retry to write? Would you envision any issue with that?
Thanks
The library doesn't currently support user-specified conditional writes. Behind the scenes, it's doing conditional writes everywhere to drive the transaction, so we didn't add the complexity of mixing in user-specified conditions with those. However, you can achieve the same functionality that a conditional write would give you by:
- Start a transaction
- Call GetItem for your item (on the tx object)
- Evaluate the condition you want to look for in your own code
- Call PutItem or UpdateItem with your changes (again, on the tx object)
- Commit the transaction
If the transaction had been rolled back, that means that a different transaction was modifying those items concurrently, and none of your writes in that transaction went through.
Thanks for the explanation!
No problem. It's a good question that we've gotten more than once, so we published a blog post describing this in more detail: http://java.awsblog.com/post/Tx13H2W58QMAOA7/Performing-Conditional-Writes-Using-the-Amazon-DynamoDB-Transaction-Library