amazon-web-services - TransactionCanceledException中的神秘TransactionConflict

标签 amazon-web-services transactions amazon-dynamodb aws-sdk

在aws-sdk(js)中使用transactWriteItems,我们得到了TransactionCanceledException。该异常内的原因为 TransactionConflict 。有时,事务中的所有操作都会失败,有时只有几个或只有一个失败。我们确实并行运行可以在同一项目上运行的多个事务。该文档没有提及此特定错误。可能原因摘录:

  1. A condition in one of the condition expressions is not met.
  2. A table in the TransactWriteItems request is in a different account or region.
  3. More than one action in the TransactWriteItems operation targets the same item.
  4. There is insufficient provisioned capacity for the transaction to be completed.
  5. An item size becomes too large (larger than 400 KB), or a local secondary index (LSI) becomes too large, or a similar validation error occurs because of changes made by the transaction.
  6. There is a user error, such as an invalid data format.


这些都不适用,并且在重试事务时似乎最终可以工作。有人知道这个异常(exception)吗?我找不到任何文件记录。

最佳答案

您遇到的不是bug,它实际上是功能的一部分,它在launch announcement 中提到。

Items are not locked during a transaction. DynamoDB transactions provide serializable isolation. If an item is modified outside of a transaction while the transaction is in progress, the transaction is canceled and an exception is thrown with details about which item or items caused the exception.


顺便说一句,DynamoDB并未使用锁定,而是使用了称为乐观并发控制的东西(也(令人困惑地)称为乐观锁定)。如果您想了解更多有关此的知识,那么Wikitia上有关Optimistic Concurrency Control的文章非常不错。
回到当前问题,用于事务的AWS documentation表示:

Multiple transactions updating the same items simultaneously can cause conflicts that cancel the transactions. We recommend following DynamoDB best practices for data modeling to minimize such conflicts.


他们专门针对TransactWriteItems说:

Write transactions don't succeed under the following circumstances:

When an ongoing TransactWriteItems operation conflicts with a concurrent TransactWriteItems request on one or more items in the TransactWriteItems operation. In this case, the concurrent request fails with a TransactionCancelledException


类似地,对于TransactGetItems:

Read transactions don't succeed under the following circumstances:

When there is an ongoing TransactGetItems operation that conflicts with a concurrent PutItem, UpdateItem, DeleteItem or TransactWriteItems request. In this case the TransactGetItems operation fails with a TransactionCancelledException

关于amazon-web-services - TransactionCanceledException中的神秘TransactionConflict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54245599/

相关文章:

c# - 使用 .NET SDK 发布到 Amazon Web Services Kinesis 时出错

amazon-web-services - AWS Spot 实例可用区

amazon-dynamodb - DynamoDB - 读取一个项目并返回一个数组大小

web-services - 列出来自公共(public)图书 API 的图书章节?

amazon-web-services - 将 docker 容器从本地推送到 aws ecr

python - 如何在不清除数据库的情况下测试 Django on_commit Hook ?

java - ActiveMQ分布式事务+扩展

hibernate - grails中的withTransaction和withSession有什么区别?

java - 通过对排序键执行 IN 操作 (begins_with (condition-expression )) 来查询 dynamoDB

linux - 在 shell 脚本中配置 aws cli 的默认输出格式