Search code examples
c#amazon-dynamodboptimistic-locking

How to clarify whether the ConditionalCheckFailedException is caused by a condition check or optimistic locking


I want to clarify whether the ConditionalCheckFailedException is caused by a condition check or optimistic locking.

It seems that there is a discussion about this issue on https://github.com/aws/aws-sdk-net/issues/1332, but I'm unsure if it has been resolved.

The reason I want to differentiate the ConditionalCheckFailedException is to implement retry logic specifically for cases related to optimistic locking, not for condition checks.

Is there a way to determine if the ConditionalCheckFailedException is due to a condition check or optimistic locking?

Thank you.


Solution

  • Update 1st July 2023

    You can choose to return the item in the case of a conditional check failure to understand which condition evaluated to false:

    Previously, condition check errors in single write operations did not return a copy of the item in the event of a condition check error. A separate read request was necessary to get the item and investigate the cause of the error. Now with the ReturnValuesOnConditionCheckFailure parameter, DynamoDB error messages can include a copy of the item as it was during the write attempt at no additional cost.

    https://aws.amazon.com/about-aws/whats-new/2023/06/amazon-dynamodb-cost-failed-conditional-writes/

    https://aws.amazon.com/blogs/database/handle-conditional-write-errors-in-high-concurrency-scenarios-with-amazon-dynamodb/