gpt4 book ai didi

java - GAE Datastore 游标是否永久且持久?

转载 作者:行者123 更新时间:2023-11-29 04:35:05 25 4
gpt4 key购买 nike

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

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

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

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

我实际上是在使用 Objectify 而不是直接使用 DS,但是据我所知,这不会影响 Cursors 相对于 Indexes 的属性。

最佳答案

游标仅在进行的原始查询的上下文中才有意义。它们不完全是索引位置/偏移量。来自 Cursors and data updates :

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.

同样来自 Limitations of cursors :

Cursors are subject to the following limitations:

  • 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).

如果您的数据没有改变,您可能可以以 map/reduce 方式使用游标(通过恢复原始查询),包括预先获取它们。

关于java - GAE Datastore 游标是否永久且持久?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41949988/

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