DynamoDB 条件写入是事务性的吗? [英] Are DynamoDB conditional writes transactional?

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

问题描述

我很难理解 DDB 提供条件写入的二分法,但 最终是一致的.这两个事实似乎相互矛盾.

在经典场景中,用户 Bob 更新密钥 A 并将值设置为FOO".用户 Alice 从尚未收到更新的节点读取,因此它得到原始值BAR".对于同一个键.

如果 Bob 和 Alice 写入集群上的不同节点没有条件检查,则可能会发生冲突,即 Alice 和 Bob 同时写入相同的密钥,而 DDB 不知道应该进行哪个更新最新的.此冲突必须由客户端在下次读取时解决.

但是什么时候使用条件写呢?

用户 Bob 将他们对 A 的更新发送为FOO".如果 A 的现有值为BAR".用户 Alice 将他们对 A 的更新发送为BAZ".如果 A 的现有值为BAR".

本地每个节点都可以检查他们的节点是否有原始的BAR".值并完成更新.但是要知道整个集群中 A 的真实状态的唯一方法是首先在整个集群中进行强一致性读取.这种强一致性读取必须阻止 Alice 或 Bob,或者他们可能同时进行强一致性读取.

所以我对 DDB 条件写入的性质感到困惑.在我看来,要么:

  1. 条件写入仅在本地评估.仍然可能发生合并冲突.
  2. 条件写入是跨集群评估的.

如果它是#2,我认为有效的唯一方法是:

  1. 为密钥创建了一个锁.
  2. 进行了高度一致的读取.

假设它是#2.现在鲍勃的更新在哪里?对节点 2 进行了更新并发送到节点 1,我们有多数法定人数.但是为了让 Alice 在他们自己的条件写入时可以使用这些更新,这些更新需要从 WAL 中刷新.那么在条件写入中是否总是刷新更新?一般来说,写入总是刷新吗?

在 SO 上还有其他类似的问题,但答案是有关此问题的 AWS 文档的重复或链接.AWS 文档并没有真正解释这一点(或者我错过了).

解决方案

DynamoDB 条件写入是事务性的".写但他们是如何完成的不是公共信息&可能是专有知识产权.

DynamoDB 开发人员是唯一拥有此信息的人.


您的问题是您从节点的角度来看这个 - 我已经浏览了


条件写入是可能跨集群评估的可能进行了高度一致的阅读,但亚马逊尚未公开此信息.

I'm having trouble wrapping my head around the dichotomy of DDB providing Condition Writes but also being eventually consistent. These two truths seem to be at odds with each other.

In the classic scenario, user Bob updates key A and sets the value to "FOO". User Alice reads from a node that hasn't received the update yet, and so it gets the original value "BAR" for the same key.

If Bob and Alice write to different nodes on the cluster without condition checks, it's possible to have a conflict where Alice and Bob wrote to the same key concurrently and DDB does not know which update should be the latest. This conflict has to be resolved by the client on next read.

But what about when condition write are used?

User Bob sends their update for A as "FOO" if the existing value for A is "BAR". User Alice sends their update for A as "BAZ" if the existing value for A is "BAR".

Locally each node can check to see if their node has the original "BAR" value and go through with the update. But the only way to know the true state of A across the cluster is to make a strongly consistent read across the cluster first. This strongly consistent read must be blocking for either Alice or Bob, or they could both make a strongly consistent read at the same time.

So here is where I'm getting confused about the nature of DDBs condition writes. It seems to me that either:

  1. Condition writes are only evaluated locally. Merge conflicts can still occur.
  2. Condition writes are evaluated cross cluster.

If it is #2, the only way I see that working is if:

  1. A lock is created for the key.
  2. A strongly consistent read is made.

Let's say it's #2. Now where does this leave Bob's update? The update was made to node 2 and sent to node 1 and we have a majority quorum. But to make those updates available to Alice when they do their own conditional write, those updates need to be flushed from WAL. So in a conditional write are the updates always flushed? Are writes always flushed in general?

There have been other questions like this here on SO but the answers were a repeat of, or a link to, the AWS documentation about this. The AWS documentation doesn't really explain this (or i missed it).

解决方案

DynamoDB conditional writes are "transactional" writes but how they're done is not public information & is perhaps proprietary intellectual property.

DynamoDB developers are the only ones with this information.


Your issue is that you're looking at this from a node perspective - I have gone through every mention of node anywhere in DynamoDB documentation & it's just mentions of Node.js or DAX nodes not database nodes.

While there can be outdated reads - yes, that would indicate some form of node - there are no database nodes per such when doing conditional writes.

User Bob sends their update for A as "FOO" if the existing value for A is "BAR". User Alice sends their update for A as "BAZ" if the existing value for A is "BAR".

Whoever's request gets there first is the one that goes through first.

The next request will just fail, meaning you now need to make a new read request to obtain the latest value to then proceed with the 2nd later write.

The Amazon DynamoDB developer guide shows this very clearly.

Note that there are no nodes, replicas etc. - there is only 1 reference to the DynamoDB table:


Condition writes are probably evaluated cross-cluster & a strongly consistent read is probably made but Amazon has not made this information public.

这篇关于DynamoDB 条件写入是事务性的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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