交易取消原因是否按与 TransactWriteItemsRequest 相同的顺序返回

Are transaction cancellation reasons returned in the same order as the TransactWriteItemsRequest

我们正在使用 DynamoDB 事务 API 执行 2 次写入:

  TransactWriteItemsRequest transactionalWriteRequest = new TransactWriteItemsRequest();
  transactionalWriteRequest.withTransactItems(writeOne, writeTwo); 
  dynamoDB.transactWriteItems(transactionalWriteRequest);

如果事务因 TransactionCanceledException 而失败,我们会返回一个包含 CancellationReason 个对象列表的异常。

在我的场景中,假设 writeOne 和 writeTwo 都失败了。异常将 return 两个取消原因。

我的问题是 - 这些原因的顺序是否与我请求中的交易顺序相匹配。

这总是正确的吗?

 // Explains why writeOne failed
 transactionError.getCancellationReasons().get(0);
 // Explains why writeTwo failed
 transactionError.getCancellationReasons().get(1);

谢谢

根据文档 - 是的,取消原因的顺序与交易项目的顺序相匹配:https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html

If using Java, DynamoDB lists the cancellation reasons on the CancellationReasons property. This property is not set for other languages. Transaction cancellation reasons are ordered in the order of requested items, if an item has no error it will have NONE code and Null message.