将实体放入Google App Engine Datastore后,无法立即使用该实体。

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

Entity is not available immediately after being put into Google App Engine Datastore

问题

我的应用程序的流程如下:

  1. 用户进入新实体页面。
  2. 用户点击保存按钮,系统将新实体放入数据存储器。
  3. 系统立即将用户重定向到编辑页面。
  4. 编辑页面对刚刚插入的实体进行查询。
  5. (问题)新插入的实体有时不可用。

我认为这是因为数据存储器需要进行一些数据复制,因此在Put(..)函数返回后,新插入的数据可能不会立即可用。我应该如何解决这个问题?是否需要使用事务处理?

英文:

My application has a flow as the followings:-

  1. User enters New Entity Page.
  2. User hits save button, the system puts the new entity into Datastore.
  3. The system redirects the user immediately to Edit page.
  4. Edit page makes a query for the newly just inserted entity.
  5. (Problem) newly inserted entity sometimes were not available.

I think it is because Datastore needs to do some data replication therefore the newly inserted data will not be available immediately after the Put(..) function returned. What should I do with the problem or do I need to use transaction?

答案1

得分: 5

你应该阅读有关最终一致性的内容:https://cloud.google.com/appengine/docs/go/datastore/structuring_for_strong_consistency

你可以进行祖先查询,或者尝试通过键引用新创建的实体。

英文:

You should read about eventual consistency: https://cloud.google.com/appengine/docs/go/datastore/structuring_for_strong_consistency

You could make an ancestor query or you could try to refer to the newly created entity by key.

huangapple
  • 本文由 发表于 2015年12月22日 17:40:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/34412688.html
匿名

发表评论

匿名网友

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

确定