保存操作期间的Dynamo DB乐观锁定行为 [英] Dynamo DB Optimistic Locking Behavior during Save Action

本文介绍了保存操作期间的Dynamo DB乐观锁定行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案:我们有一个Dynamo DB表,该表支持带有版本号的乐观锁定。两个并发线程正在尝试将具有相同主键值的两个不同条目保存到该表中。

Scenario: We have a Dynamo DB table supporting Optimistic Locking with Version Number. Two concurrent threads are trying to save two different entries with the same primary key value to that Table.

问题:是否为后者的保存操作抛出ConditionalCheckFailedException?

Question: Will ConditionalCheckFailedException be thrown for the latter save action?

推荐答案

是,第二个尝试插入相同数据的线程将抛出 ConditionalCheckFailedException

Yes, the second thread which tries to insert the same data would throw ConditionalCheckFailedException.

com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException

保存在数据库中,随后的更新应具有与DynamoDB表中的值(即服务器端值)匹配的版本。

As soon as the item is saved in database, the subsequent updates should have the version matching with the value on DynamoDB table (i.e. server side value).


保存—对于新项目,DynamoDBMapper分配了一个初始版本
数字1。如果检索一个项目,更新其
属性中的一个或多个并尝试保存更改,则保存操作
成功。仅当客户端和
服务器上的版本号匹配时。 DynamoDBMapper自动增加版本号

save — For a new item, the DynamoDBMapper assigns an initial version number 1. If you retrieve an item, update one or more of its properties and attempt to save the changes, the save operation succeeds only if the version number on the client-side and the server-side match. The DynamoDBMapper increments the version number automatically.

这篇关于保存操作期间的Dynamo DB乐观锁定行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆