简体   繁体   English

在DynamoDB中保存和删除项目时使用DynamoDBMapperConfig Clobber或Update

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

I have a DynamoDB table with 3 GSI's. 我有一个带有3个GSI的DynamoDB表。 I need to perform only 3 operations on table - save, delete and get. 我只需要对表执行3个操作-保存,删除和获取。 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: 以下是AWS文档,介绍了不同的保存行为:

https://aws.amazon.com/blogs/developer/using-the-savebehavior-configuration-for-the-dynamodbmapper/ 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. 我知道您是说您只关心保存/读取/删除而不是更新,但是您必须记住DynamoDB不是事务数据库。 So you have to think about retries and idempotence. 因此,您必须考虑重试和幂等性。 There's the delivery mechanism of DynamoDB's execution itself. DynamoDB本身具有执行机制。 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) 现在它在某种意义上可能不是“问题”(因为您已经保证以某种方式始终传播相同的信息),但是DynamoDB不知道,因此您必须回答该问题(或留空以使用默认行为)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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