When a TransactionWriteRequest contains an operation that updates an object with a field with the@DynamoDBVersionAttribute annotation DynamoDBMapper throws the following exception:
com.amazonaws.SdkClientException: Versioned attributes are not supported on TransactionWrite API
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.generateTransactWriteItem(DynamoDBMapper.java:2449)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.transactionWrite(DynamoDBMapper.java:1116)
at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.transactionWrite(AbstractDynamoDBMapper.java:163)
Which is thrown because of the following check:
if (field.versioned()) {
throw new SdkClientException("Versioned attributes are not supported on TransactionWrite API");
}
What is the reason behind this check?
Is this temporary and support for versioned fields will be added later or versioned fields are fundamentally incompatible with DynamoDB transactions?
Hi @mushketyk, it's the latter option, versioned fields are not supported by DynamoDBMapper transactional operations, as mentioned in the Optimistic Locking With Version Number docs.
This is not a fundamental limitation. It wasn't straight-forward to make versioning work with string condition expressions, so that work was punted for later. Options are currently being evaluated to support versioning in transactionWrite API.
@mushketyk could you give a little more context on your use-case? Do you specify any conditions on the objects with a field with the @DynamoDBVersionAttribute annotation?
@kapilsingh5050 I am not running this in production, I am just exploring this new feature to see how it works.
Do you specify any conditions on the objects with a field with the @DynamoDBVersionAttribute annotation?
I don't specify any conditions. It seems that the exception is thrown for any update operation that updates a table for a class with the @DynamoDBVersionAttibute attribute. So this seems like a significant limitation
Options are currently being evaluated to support versioning in transactionWrite API.
Would it make sense to automatically add an update operation to increment a version field and expect a user to add a condition expression to check a version field if this is needed?
Or alternatively, would it make sense to just expect a user to add updates/checks for a version field?
Any update on this?
Also interested. Having both multi-document and multi-table transactions with optimistic locking is extremely important for data integrity.
Also interested. Having both multi-document and multi-table transactions with optimistic locking is extremely important for data integrity.
+1
@DynamoDBVersionAttribute is supported in transaction API calls now. Check https://aws.amazon.com/about-aws/whats-new/2019/10/dynamodbmapper-now-supports-optimistic-locking-for-amazon-dynamodb-transactional-api-calls/ @mushketyk @zzx88991 @celluj34 @dcsena FYI
Most helpful comment
Also interested. Having both multi-document and multi-table transactions with optimistic locking is extremely important for data integrity.