英文:
Entity is not available immediately after being put into Google App Engine Datastore
问题
我的应用程序的流程如下:
- 用户进入新实体页面。
- 用户点击保存按钮,系统将新实体放入数据存储器。
- 系统立即将用户重定向到编辑页面。
- 编辑页面对刚刚插入的实体进行查询。
- (问题)新插入的实体有时不可用。
我认为这是因为数据存储器需要进行一些数据复制,因此在Put(..)函数返回后,新插入的数据可能不会立即可用。我应该如何解决这个问题?是否需要使用事务处理?
英文:
My application has a flow as the followings:-
- User enters New Entity Page.
- User hits save button, the system puts the new entity into Datastore.
- The system redirects the user immediately to Edit page.
- Edit page makes a query for the newly just inserted entity.
- (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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论