GAE Golang – 在保存数据后,查询没有立即返回数据。

huangapple go评论87阅读模式
英文:

GAE Golang - queries not returning data right after it is saved

问题

我正在编写一个使用Google App Engine Go的应用程序,并且在测试某些功能时遇到了问题。这里有一些示例代码。 问题如下:

  1. 我创建一个新项目并将其保存到数据存储中。
  2. 我立即进行搜索查询以查找该项目(例如,获取命名空间中的所有项目)。
  3. 该项目不存在。

如果我稍后查询该项目(例如,在后续页面中),则可以正常找到该项目。我理解这种行为可能是GAE上部署的应用程序的意图,但我希望本地数据存储立即对查询有效。

有没有办法强制数据存储合并并对此类查询有效?

英文:

I am writing a Google App Engine Go application and I'm having problem in testing some functionality. Here is some sample code. The problem is as follows:

  1. I create a new item and save it to datastore
  2. I make a search query for that item immediately after (for example, getting all items in the namespace)
  3. The item is not there

If I query for the item later (say, in subsequent pages), the item is found normally. I understand this behaviour might be intentional for apps deployed on GAE, but I would expect the local datastore to be instantly good for queries.

Is there any way I can force the datastore to consolidate and be good for such queries?

答案1

得分: 3

这被称为最终一致性,是App Engine的Datastore的一个特性。

您可以使用get方法而不是查询来测试实体是否已保存。

在Java中,我们可以通过更改运行参数来设置本地数据存储的期望行为:

默认情况下,本地数据存储配置为模拟高复制数据存储的一致性模型,其中在全局查询中不立即可见的数据存储写入的百分比设置为10%。

要调整此一致性级别,请使用与您希望应用程序看到的最终一致性量相对应的值设置datastore.default_high_rep_job_policy_unapplied_job_pct系统属性。

我找不到类似的Go语言的设置。

英文:

This is called eventual consistency, and it's a feature of App Engine's Datastore.

You can use a get method instead of a query to test if an entity has been saved.

In Java we can set the desired behavior of a local datastore by changing a run parameter:

> By default, the local datastore is configured to simulate the
> consistency model of the High Replication Datastore, with the
> percentage of datastore writes that are not immediately visible in
> global queries set to 10%.
>
> To adjust this level of consistency, set the
> datastore.default_high_rep_job_policy_unapplied_job_pct system
> property with a value corresponding to the amount of eventual
> consistency you want your application to see.

I could not find something similar for Go.

huangapple
  • 本文由 发表于 2014年6月18日 16:49:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/24281103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定