GAE Datastore游标是否永久且持久? [英] Are GAE Datastore cursors permanent and durable?

查看:81
本文介绍了GAE Datastore游标是否永久且持久?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

com.google.appengine.api.datastore.Cursor 只是将索引位置存储到GAE数据存储索引中是否正确?

Is it correct to say that a com.google.appengine.api.datastore.Cursor simply stores an index position into a GAE Datastore index?

游标耐用吗?也就是说,我是否可以永久存储一个游标并一次又一次地重复使用它,以确保可以肯定它是否指向索引中的第5000个位置?

Are cursors durable? That is, can I store a cursor permanently and reuse it again and again knowing for sure that if it was pointing to 5000th position in the index, that's where it'll point forever?

如果索引缩小到少于5000个条目怎么办?使用此游标会导致错误还是什么都不返回?

What if the index shrinks to less than 5000 entries? Will using this cursor cause an error or simply return nothing?

对于较大的索引(例如,100,000个或更多的条目),我可以先获取每5000倍的游标吗?位置(例如),存储它们,然后使用这组游标以Map / Reduce方式完成某些工作?

For larger indexes (say 100,000 or more entries), can I first acquire cursors for every multiple-of-5000th position (say), store them and then use this set of cursors to do some work in a Map/Reduce manner?

我实际上是在使用Objectify而不是直接使用DS ,但是AFAIK不会影响游标相对于索引的属性。

I am actually using Objectify and not the DS directly, but AFAIK this will not affect the properties of Cursors vis-a-vis Indexes.

推荐答案

游标仅在上下文中有意义进行的原始查询。它们不完全是索引位置/偏移量。来自光标和数据更新

Cursors only make sense in the context of the original query that was made. They are not exactly index positions/offsets. From Cursors and data updates:


将光标的位置定义为结果列表
在返回最后一个结果之后的位置。光标不是列表
中的相对位置(不是偏移量);这是开始对结果进行索引扫描时Cloud Datastore
可以跳转到的标记。如果
查询的结果在两次使用游标之间发生变化,则查询仅注意到在游标之后的结果中发生的
变化。如果新结果出现在查询的光标位置
之前,则在获取光标后的
结果时不会返回该结果。同样,如果一个实体不再是
的查询结果,而是出现在光标之前,则在光标之后出现的
结果不会更改。如果从结果集中删除了返回的最后一个结果
,则光标仍然知道
如何定位下一个结果。

The cursor's position is defined as the location in the result list after the last result returned. A cursor is not a relative position in the list (it's not an offset); it's a marker to which Cloud Datastore can jump when starting an index scan for results. If the results for a query change between uses of a cursor, the query notices only changes that occur in results after the cursor. If a new result appears before the cursor's position for the query, it will not be returned when the results after the cursor are fetched. Similarly, if an entity is no longer a result for a query but had appeared before the cursor, the results that appear after the cursor do not change. If the last result returned is removed from the result set, the cursor still knows how to locate the next result.

也来自游标的限制


游标受到以下限制:

Cursors are subject to the following limitations:


  • 游标只能由执行原始查询的同一应用程序使用,并且只能继续同一查询。要在随后的检索操作中使用游标
    ,必须完全重构
    原始查询,包括相同的实体类型,祖先
    过滤器,属性过滤器和排序顺序。
    不能使用游标检索结果,而无需从最初生成的
    中设置相同的查询。

  • 因为实现了NOT_EQUAL和IN运算符对于多个查询,使用它们的查询不支持游标,也不使用CompositeFilterOperator.or
    方法构造的
    复合查询。

  • 游标并不总是有效与使用不等式过滤器或对具有多个值的属性的排序顺序的查询所期望的一样。
    此类多值属性的重复数据删除逻辑不会在两次检索之间保持
    不变,可能会导致相同的结果是
    多次返回。

  • 新版App Engine版本可能会更改内部实现细节,从而使依赖于它们的游标无效。如果应用程序
    尝试使用不再有效的游标,则Cloud Datastore
    会引发IllegalArgumentException(低级API),
    JDOFatalUserException(JDO)或PersistenceException(JPA)。 / li>
  • A cursor can be used only by the same application that performed the original query, and only to continue the same query. To use the cursor in a subsequent retrieval operation, you must reconstitute the original query exactly, including the same entity kind, ancestor filter, property filters, and sort orders. It is not possible to retrieve results using a cursor without setting up the same query from which it was originally generated.
  • Because the NOT_EQUAL and IN operators are implemented with multiple queries, queries that use them do not support cursors, nor do composite queries constructed with the CompositeFilterOperator.or method.
  • Cursors don't always work as expected with a query that uses an inequality filter or a sort order on a property with multiple values. The de-duplication logic for such multiple-valued properties does not persist between retrievals, possibly causing the same result to be returned more than once.
  • New App Engine releases might change internal implementation details, invalidating cursors that depend on them. If an application attempts to use a cursor that is no longer valid, Cloud Datastore raises an IllegalArgumentException (low-level API), JDOFatalUserException (JDO), or PersistenceException (JPA).

如果您的数据不变,则可以通过地图/缩小方式使用游标(通过还原原始查询),包括预先获取它们。

If your data doesn't change you're probably OK using cursors in a map/reduce manner (by restoring the original query), including pre-acquiring them.

这篇关于GAE Datastore游标是否永久且持久?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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