亚马逊-DynamoDB一致性强的读物,它们是最新的吗? [英] Amazon - DynamoDB Strong consistent reads, Are they latest and how?

查看:117
本文介绍了亚马逊-DynamoDB一致性强的读物,它们是最新的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图将Dynamodb用于其中一个项目时,我对dynamodb的强一致性模型有疑问。从常见问题解答中


严格一致的读取—除了最终的一致性外,Amazon DynamoDB还为您提供了
的灵活性和控制权如果您的应用程序或应用程序的某个元素需要它,则该内容应具有高度一致性。高度一致的读取返回一个结果,该结果反映了在读取之前收到成功响应的所有写入。


根据上面的定义,我得到的是,强一致性读取将返回最新的写入值。



以示例为例:假设Client1在密钥K1上发出了一个写入命令以从V0更新值到V1几毫秒后,Client2发出密钥K1的读取命令,则在始终保持强一致性的情况下,始终会返回V1,但是在最终保持一致性的情况下,可能会返回V1或V0。我的理解正确吗?



如果是,如果写操作返回成功但数据未更新到所有副本并且我们发出强一致性读取该怎么办,它将如何确保返回



以下链接
试图解释其背后的体系结构,但不知道是否这实际上是如何工作的?经过此链接后,我想到的下一个问题是:DynamoDb是基于单主机,多从机体系结构的,其中写入和强一致性读取是通过主副本进行的,而正常读取是通过其他副本进行的。

简短答案:在强一致性模式下成功写入要求您在大多数可以包含该记录的服务器上成功写入,因此任何将来的一致性读取将始终看到相同的数据,因为一致的读取必须读取可以包含所需记录的大多数服务器。如果您未执行强一致性读取,则系统将向随机服务器询问记录,并且数据可能不是最新的。



<想象一下三台服务器。服务器1,服务器2和服务器3。要写入高度一致的记录,请至少选择两个服务器,然后写入数据。让我们选择1和2。



现在您要始终读取数据。选择大多数服务器。假设我们选择了2和3。



服务器2具有新数据,这就是系统返回的数据。



最终一致的读取可能来自服务器1、2或3。这意味着,如果服务器3是随机选择的,则直到复制发生,您的新写入才会出现。



如果单个服务器发生故障,您的数据仍然是安全的,但是如果三分之二的服务器发生故障,则在脱机服务器恢复之前,新的写入操作可能会丢失。



更多说明:
DynamoDB (假设它类似于Amazon发布的Dynamo论文中描述的数据库)使用环形拓扑,其中数据分散到许多服务器。由于您直接查询所有相关服务器并从中获取当前数据,因此可以确保强大的一致性。环中没有主设备,环中没有从设备。给定的记录将映射到环中许多相同的主机,所有这些服务器将包含该记录。没有奴隶可以落后,也没有主人可以失败。



可以自由阅读有关该主题的许多论文。可以使用类似的名为Apache Cassandra的数据库,该数据库也使用环形复制。



http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/decandia07dynamo.pdf


In an attempt to use Dynamodb for one of projects, I have a doubt regarding the strong consistency model of dynamodb. From the FAQs

Strongly Consistent Reads — in addition to eventual consistency, Amazon DynamoDB also gives you the flexibility and control to request a strongly consistent read if your application, or an element of your application, requires it. A strongly consistent read returns a result that reflects all writes that received a successful response prior to the read.

From the definition above, what I get is that a strong consistent read will return the latest write value.

Taking an example: Lets say Client1 issues a write command on Key K1 to update the value from V0 to V1. After few milliseconds Client2 issues a read command for Key K1, then in case of strong consistency V1 will be returned always, however in case of eventual consistency V1 or V0 may be returned. Is my understanding correct?

If it is, What if the write operation returned success but the data is not updated to all replicas and we issue a strongly consistent read, how it will ensure to return the latest write value in this case?

The following link AWS DynamoDB read after write consistency - how does it work theoretically? tries to explain the architecture behind this, but don't know if this is how it actually works? The next question that comes to my mind after going through this link is: Is DynamoDb based on Single Master, multiple slave architecture, where writes and strong consistent reads are through master replica and normal reads are through others.

解决方案

Short answer: Writing successfully in strongly consistent mode requires that your write succeed on a majority of servers that can contain the record, therefore any future consistent reads will always see the same data, because a consistent read must read a majority of the servers that can contain the desired record. If you do not perform a strongly consistent read, the system will ask a random server for the record, and it is possible that the data will not be up-to-date.

Imagine three servers. Server 1, server 2 and server 3. To write a strongly consistent record, you pick two servers at minimum, and write the data. Let's pick 1 and 2.

Now you want to read the data consistently. Pick a majority of servers. Let's say we picked 2 and 3.

Server 2 has the new data, and this is what the system returns.

Eventually consistent reads could come from server 1, 2, or 3. This means if server 3 is chosen by random, your new write will not appear yet, until replication occurs.

If a single server fails, your data is still safe, but if two out of three servers fail your new write may be lost until the offline servers are restored.

More explanation: DynamoDB (assuming it is similar to the database described in the Dynamo paper that Amazon released) uses a ring topology, where data is spread to many servers. Strong consistency is guaranteed because you directly query all relevant servers and get the current data from them. There is no master in the ring, there are no slaves in the ring. A given record will map to a number of identical hosts in the ring, and all of those servers will contain that record. There is no slave that could lag behind, and there is no master that can fail.

Feel free to read any of the many papers on the topic. A similar database called Apache Cassandra is available which also uses ring replication.

http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/decandia07dynamo.pdf

这篇关于亚马逊-DynamoDB一致性强的读物,它们是最新的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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