3

In the App Engine Documentation I found an interesting strategy for keeping up to date with changes in the datastore by using 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.

However, I'm not quite sure how this can always work. After all, when using the High Replication Datastore, queries are only eventually consistent. So if two entities are put, and only the later of the two is seen by the query, it will move the cursor past both of them. Which will mean that the first of the two new entities will remain unseen.

So is this an actual issue? Or is there some other way that cursors work around this?

4

2 回答 2

3

在包含单调递增值(例如当前时间戳)的属性上具有内置或复合索引,在高写入速率下可能无法达到您想要的效果。这种类型的工作负载将产生一个热点,因为索引的尾部会不断更新,而不是负载分布在整个排序索引中。但是,对于低写入率,这将正常工作。

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

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

如果您要查询许多实体组,这些实体组始终是最终一致的,则无法保证写入应用/可见的顺序。例如: - Time1 - 写入 EntityA - Time2 - 写入 EntityB - Time3 - 查询只看到 EntityB - Time4 - 查询看到 EntityA 和 EntityB

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

有关最终/强一致性的更多信息,请参阅使用 Google Cloud Datastore 平衡强一致性和最终一致性

于 2013-12-06T21:46:10.917 回答
1

如果您可以询问从事此工作的人,您可能会得到最好的信息,但是在考虑一下并重新阅读 Paxos 之后,我认为这应该不是问题,尽管这取决于数据存储的实际情况实施的。

游标本质上是索引中的一个位置。从理论上讲,您可以一遍又一遍地重新阅读相同的光标,并看到新的实体开始出现在它之后。在现实世界的情况下,您通常会移动到最新的光标位置而忘记旧的光标位置。

最终一致性“问题”出现是因为索引的多个副本分布在多台机器上。根据您读取的索引,您可能会得到陈旧的结果。

您描述了一个问题案例,其中索引 I 有两个(精确)副本,并创建了两个新实体 E1 和 E2。假设 I1 = I + E1 和 I2 = I + E2,因此根据您读取的索引,您可能会将 E1 或 E2 作为新实体,移动光标,并在索引“修补”时错过实体其他索引,即 I2 最终被修补为 I + E1 + E2。

如果数据存储确实以这种方式发生,那么我怀疑,是的,您可能会遇到问题。但是,这样操作听起来非常困难,而且我怀疑数据存储索引只有在 Paxos 投票达成协议后才会更新。所以你永远不会看到乱序索引,你只会看到迟到的实体:也就是说,你永远不会看到 I + E2,你只会看到 (I) 或 (I + E1)或 (I + E1 + E2)

不过我怀疑,您可能会遇到一个问题,即您可能拥有一个对于尚未赶上的索引来说太新的游标。

于 2013-12-06T21:02:03.433 回答