gpt4 book ai didi

google-app-engine - 游标是否处理最终一致性?

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:34 25 4
gpt4 key购买 nike

我在 App Engine 文档中找到了 an interesting strategy通过使用 Cursors 与数据存储中的更改保持同步:

An interesting application of cursors is to monitor entities for unseen changes. If the app sets a timestamp property with the current date and time every time an entity changes, the app can use a query sorted by the timestamp property, ascending, with a Datastore cursor to check when entities are moved to the end of the result list. If an entity's timestamp is updated, the query with the cursor returns the updated entity. If no entities were updated since the last time the query was performed, no results are returned, and the cursor does not move.

但是,我不太确定这如何始终有效。毕竟,在使用 High Replication Datastore 时,查询只是最终一致的。因此,如果放置了两个实体,并且查询只看到了两者中的较晚者,它会将光标移过它们的两者。这意味着两个新实体中的第一个将保持不可见状态。

那么这是一个实际问题吗?还是有其他方法可以让游标解决这个问题?

最佳答案

在包含单调递增值(例如当前时间戳)的属性上使用内置索引或复合索引,在高写入速率下可能无法像您希望的那样执行。这种类型的工作负载会产生一个热点,因为索引的尾部不断更新,而不是负载分布在整个排序索引中。然而,对于低写入率,这会很好地工作。

其余的答案将取决于您是属于同一实体组还是不同的实体组。

如果您的查询是祖先查询,因此在同一个实体组中它可以是高度一致的(默认情况下它们是),并且所描述的方法应该始终是准确的。查询将立即看到任何写入(对实体组内实体的更改)。

如果您正在查询多个实体组,这始终是最终一致的,那么就无法保证写入的应用/可见顺序。例如:- Time1 - 写入实体A- Time2 - 写入实体B- 时间 3 - 查询只看到 EntityB- 时间 4 - 查询看到实体 A 和实体 B

所以使用游标检测变化的方法是正确的,但它可能会“跳过”一些变化。

有关最终/强一致性的更多信息,请参阅 Balancing Strong and Eventual consistency with Google Cloud Datastore

关于google-app-engine - 游标是否处理最终一致性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20429807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com