DynamoDB一致读取全球次级指数 [英] DynamoDB consistent reads for Global Secondary Index

查看:391
本文介绍了DynamoDB一致读取全球次级指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不能我得到一致的全球仲索引读取?

Why cant I get consistent reads for global-secondary-indexes?

我有以下设置:

表:向tblUsers (ID哈希)

全局二级索引: tblUsersEmailIndex (电子邮件作为哈希,id作为属性)

Global Secondary Index: tblUsersEmailIndex (email as hash, id as attribute)

全局二级索引: tblUsersUsernameIndex (用户名作为哈希,id作为属性)

Global Secondary Index: tblUsersUsernameIndex (username as hash, id as attribute)

我查询索引来检查,如果给定电子邮件或用户名是present,所以我不创建一个重复的用户。

I query the indexes to check if a given email or username is present, so I dont create a duplicate user.

现在的问题是我不能做一致的读取查询的索引。但是,为什么不呢?这是为数不多的场合之一,其实我的需求的向上的最新数据。

Now, the problem is I cant do consistent reads for queries on the indexes. But why not? This is one of the few occasions I actually need up-to-date data.

据AWS文档:

在全球二级索引的查询只支持最终一致性。

Queries on global secondary indexes support eventual consistency only.

变化表数据将被传播到全局二次索引的几分之一秒内,在正常条件下。然而,在一些不太可能故障的情况下,可能会出现较长的传播延迟。正因为如此,您的应用程序需要预见和处理的情况下,在全球二级索引返回结果是一个查询没有及时更新

Changes to the table data are propagated to the global secondary indexes within a fraction of a second, under normal conditions. However, in some unlikely failure scenarios, longer propagation delays might occur. Because of this, your applications need to anticipate and handle situations where a query on a global secondary index returns results that are not up-to-date.

但我怎么处理这种情况?我怎样才能确保给定电子邮件或用户名尚未present在db?

But how do i handle this situation? How can I make sure that a given email or username is not already present in the db?

推荐答案

您可能已经通过这个去:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide /GSI.html

You probably already went through this: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html

简短的回答是要与全球辅助索引做什么你不能这样做(即它总是最终一致性)。

The short answer is that you cannot do what you want to do with Global Secondary Indexes (ie it's always eventual consistency).

一个解决方案,这里将有一个单独的表瓦特/属性你有兴趣作为重点,并做持续读那里。您将需要确保您要更新,只要你插入新的实体,而你也会担心其插入有成功的边缘的情况下,而不是在主表(即你需要确保它们保持同步)

A solution here would be to have a separate table w/ the attribute you're interested in as a key and do consistent reads there. You would need to ensure you are updating that whenever you are inserting new entities, and you would also have to worry about the edge case in which inserts there succeed, but not in the main table (ie you need to ensure they are in sync)

另一个解决方案是扫描整个表,但是这很可能是矫枉过正,如果表是很大的。

Another solution would be to scan the whole table, but that would probably be overkill if the table is large.

你为什么关心,如果有人创建2个帐户使用相同的电子邮件?你可以只使用用户名作为主散列键,只是不强制邮件唯一性。

Why do you care if somebody creates 2 accounts with the same email? You could just use the username as the primary hash key and just not enforce the email uniqueness.

这篇关于DynamoDB一致读取全球次级指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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