aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

DynamoDBMapper: Versioned attributes not supported with transactions

Open mushketyk opened this issue 7 years ago • 11 comments

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?

mushketyk avatar May 14 '19 19:05 mushketyk

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.

debora-ito avatar May 14 '19 22:05 debora-ito

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.

kapilsingh5050 avatar May 14 '19 23:05 kapilsingh5050

@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 avatar May 14 '19 23:05 kapilsingh5050

@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?

mushketyk avatar May 15 '19 08:05 mushketyk

Any update on this?

dcsena avatar Aug 29 '19 16:08 dcsena

Also interested. Having both multi-document and multi-table transactions with optimistic locking is extremely important for data integrity.

celluj34 avatar Aug 30 '19 18:08 celluj34

Also interested. Having both multi-document and multi-table transactions with optimistic locking is extremely important for data integrity.

+1

zzx88991 avatar Sep 11 '19 19:09 zzx88991

@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

vnpandey avatar Oct 15 '19 17:10 vnpandey

Hello guys. Could you please advise if this has also been implemented in .NET SDK?

oleksandr-bulakaiev-rft avatar Jul 06 '21 14:07 oleksandr-bulakaiev-rft

@oleksandr-bulakaiev-rft the folks of the .NET SDK team should be able to answer that in the .NET SDK repo: https://github.com/aws/aws-sdk-net

debora-ito avatar Jul 21 '21 23:07 debora-ito

versioned attribute now is supported in ddb transaction operations in aws.java.sdk 1.12.300 . it is tested in my side.

weibian-wyze avatar Sep 14 '22 08:09 weibian-wyze