简体   繁体   中英

Using DynamoDBMapperConfig Clobber or Update when saving and deleting an item from DynamoDB

I have a DynamoDB table with 3 GSI's. I need to perform only 3 operations on table - save, delete and get. All the items will be unique. I am confused which one will be better -

I have following variables -

ddbMapperConfigClobber = new DynamoDBMapperConfig.Builder().withConsistentReads(
            DynamoDBMapperConfig.ConsistentReads.CONSISTENT)
            .withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.CLOBBER).build();


ddbMapperConfigUpdate = new DynamoDBMapperConfig.Builder().withConsistentReads(
            DynamoDBMapperConfig.ConsistentReads.CONSISTENT)
            .withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.UPDATE).build();

Which one should i use for save

ddbMapper.save(item, ddbMapperConfigUpdate); or  ddbMapper.save(item, ddbMapperConfigClobber);

Which one should i use for delete -

ddbMapper.delete(item,ddbMapperConfigClobber); or ddbMapper.delete(item,ddbMapperConfigUpdate);

Here is the AWS Documentation describing the different save behaviors:

https://aws.amazon.com/blogs/developer/using-the-savebehavior-configuration-for-the-dynamodbmapper/

Each has different behavior when the item exists.

I know you are saying that you only care about save/read/delete and not update, but you have to remember that DynamoDB is not a Transactional Database. So you have to think about retries and idempotence. There's the delivery mechanism of DynamoDB's execution itself. And there's the caller's guarantee level (ie at least once, at most once, etc).

So whether you like it or not, you do have to care about the update. Now it may not "matter" in a sense (because you've somehow guaranteed that the same info always propagates), but DynamoDB doesn't know that so you have to answer the question (or leave it blank to use the default behavior)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM