DynamoDB 并发写入 [英] DynamoDB concurrent write

查看:23
本文介绍了DynamoDB 并发写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的 DynamoDB 表,其中包含属性说

<上一页>----------------------------------------------------------hk(哈希键)|rk(范围键)|a1 |a2 |a3 |----------------------------------------------------------


我有一个现有的 DynamoDb 客户端,它只会更新 a1 的现有记录.我想创建第二个编写器(DDB 客户端),它也将更新现有记录,但仅适用于 a2 和 a3.
如果 ddb 客户端同时尝试更新同一条记录(a1 为 1,a2 和 a3 为另一个),DynamoDb 是否会保证所有 a1 a2 a3 都更新为正确的值(所有三个新值)?使用保存行为 UPDATE_SKIP_NULL_ATTRIBUTES 是否足以达到此目的,或者我是否需要实现某种乐观锁定?如果不,DDB 是否为此目的即时提供了一些东西?

解决方案

如果您碰巧使用的是 Dynamo Java SDK,那么您很幸运,因为 SDK 通过 乐观锁定.我不确定其他 SDK 是否支持类似的东西 - 我怀疑他们不支持.

<块引用>

乐观锁定是一种确保客户端项的策略您正在更新(或删除)的项目与动态数据库.如果你使用这个策略,那么你的数据库写入是防止被其他人的写入覆盖 - 和反之亦然.

I have an existing DynamoDB table which has attributes say

---------------------------------------------------------
hk(hash-key)| rk(range-key)|   a1    |    a2   |    a3   | 
---------------------------------------------------------


I have an existing DynamoDb client which will only update existing record for a1 only. I want to create a second writer(DDB client) which will also update an existing record, but, for a2 and a3 only.
If both the ddb client tries to update same record (1 for a1 and other for a2 and a3) at the exact same time, will DynamoDb guarantee that all a1 a2 a3 are updated with correct value(all three new values)? Is using save behavior UPDATE_SKIP_NULL_ATTRIBUTES sufficient for this purpose or do I need to implement some kind of optimistic locking? If not, Is there something that DDB provides on the fly for this purpose?

解决方案

If you happen to be using the Dynamo Java SDK you are in luck, because the SDK supports just that with Optimistic Locking. Im not sure if the other SDKs support anything similar - I suspect they do not.

Optimistic locking is a strategy to ensure that the client-side item that you are updating (or deleting) is the same as the item in DynamoDB. If you use this strategy, then your database writes are protected from being overwritten by the writes of others — and vice-versa.

这篇关于DynamoDB 并发写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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