gpt4 book ai didi

python - 在 App Engine Python 中设置读取策略

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

this document据说默认的 read_policy 设置是ndb.EVENTUAL_CONSISTENCY。

在我从应用程序的数据存储版本中批量删除实体项目后,我继续读取旧数据,因此我尝试找出如何将其更改为STRONG_CONSISTENCY没有成功,包括:

  • entity.query().fetch(read_policy=ndb.STRONG_CONSISTENCY)
  • ...fetch(options=ndb.ContextOptions(read_policy=ndb.STRONG_CONSISTENCY))

我得到的错误是

BadArgumentError: read_policy argument invalid ('STRONG_CONSISTENCY')

如何更改此默认值?更重要的是,如何确保 NDB 将前往数据存储区加载结果而不是依赖于旧的缓存值? (请注意,批量删除后,数据存储浏览器告诉我该实体已消失。)

最佳答案

您无法更改该默认值,它也是唯一可用的选项。从您引用的文档中(没有提到其他选项):

Description

Set this to ndb.EVENTUAL_CONSISTENCY if, instead of waiting for the Datastore to finish applying changes to all returned results, you wish to get possibly-not-current results faster.

通过检查 google.appengine.ext.ndb.context.py 文件(其中没有 STRONG_CONSISTENCY 定义)可以确认这一点:

# Constant for read_policy.
EVENTUAL_CONSISTENCY = datastore_rpc.Configuration.EVENTUAL_CONSISTENCY

EVENTUAL_CONSISTENCY 通过 google.appengine.ext.ndb.__init__.py 最终到达 ndb:

from context import *
__all__ += context.__all__

也许可以使用如下的 hack 来避免错误:

from google.appengine.datastore.datastore_rpc import Configuration

...fetch(options=ndb.ContextOptions(read_policy=Configuration.STRONG_CONSISTENCY))

但是我认为仅适用于读取通过查询获得的键的实体,而不适用于获取键本身的列表,该列表来自查询使用的索引,该索引始终是最终一致 - 删除的实体仍然出现在结果中的根本原因(一段时间,直到索引更新)。来自 Keys-only Global Query Followed by Lookup by Key :

But it should be noted that a keys-only global query can not exclude the possibility of an index not yet being consistent at the time of the query, which may result in an entity not being retrieved at all. The result of the query could potentially be generated based on filtering out old index values. In summary, a developer may use a keys-only global query followed by lookup by key only when an application requirement allows the index value not yet being consistent at the time of a query.

可能感兴趣:Bulk delete datastore entity older than 2 days

关于python - 在 App Engine Python 中设置读取策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49515361/

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