Appengine - 在放入某些内容后立即查询数据库

发布于 2024-12-16 12:56:50 字数 280 浏览 4 评论 0原文

在代码的一个地方,我做了这样的事情:

FormModel(.. some data here..).put()

下面的几行是我从数据库中选择的:

FormModel.all().filter(..).fetch(100)

我注意到的问题 - 有时提取没有注意到我刚刚添加的数据。

我的理论是,发生这种情况是因为我使用的是高复制存储,并且没有给它足够的时间来复制数据。但我怎样才能避免这个问题呢?

In one place of code I do something like this:

FormModel(.. some data here..).put()

And a couple lines below I select from the database:

FormModel.all().filter(..).fetch(100)

The problem I noticed - sometimes the fetch doesn't notice the data I just added.

My theory is that this happens because I'm using high replication storage, and I don't give it enough time to replicate the data. But how can I avoid this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不即不离 2024-12-23 12:56:50

除非数据位于同一实体组中,否则无法保证数据是最新的数据(如果我 正确理解本节)。

Unless the data is in the same entity group there is no way to guarantee that the data will be the most up to data (If I understand this section correctly).

芯好空 2024-12-23 12:56:50

Shay 是对的:没有办法知道数据存储区何时准备好返回您刚刚输入的数据。

但是,一旦对 put 的调用成功完成,您可以保证最终会输入数据。这是大量信息,您可以使用它来解决此问题。当您从 fetch 获取数据时,只需附加/插入您知道最终将位于其中的新实体即可!我认为,在大多数情况下,在每个请求的基础上执行此操作就足够了,但您可以做一些更强大的操作,使用 memcache 来覆盖所有请求(除了 memcache 失败的情况)。

当然,困难的部分是弄清楚何时应该附加/插入哪些实体。必须采取这种解决方法是令人讨厌的,但对于像 HRD 这样复杂得惊人的事情来说,付出的代价相对较低。

Shay is right: there's no way to know when the datastore will be ready to return the data you just entered.

However, you are guaranteed that the data will be entered eventually, once the call to put completes successfully. That's a lot of information, and you can use it to work around this problem. When you get the data back from fetch, just append/insert the new entities that you know will be in there eventually! In most cases it will be good enough to do this on a per-request basis, I think, but you could do something more powerful that uses memcache to cover all requests (except cases where memcache fails).

The hard part, of course, is figuring out when you should append/insert which entities. It's obnoxious to have to do this workaround, but a relatively low price to pay for something as astonishingly complex as the HRD.

一笑百媚生 2024-12-23 12:56:50

来自 https://developers.google.com/appengine/docs/java/数据存储/事务#Java_Isolation_and_consistency

这种一致的快照视图还扩展到写入后读取
内部交易。与大多数数据库不同,查询和获取
在数据存储区事务中看不到先前的结果
写入该事务内。 具体来说,如果实体被修改
或在事务中删除,查询或获取返回原始
截至交易开始时实体的版本,或
如果该实体当时不存在,则什么也没有。

From https://developers.google.com/appengine/docs/java/datastore/transactions#Java_Isolation_and_consistency

This consistent snapshot view also extends to reads after writes
inside transactions. Unlike with most databases, queries and gets
inside a Datastore transaction do not see the results of previous
writes inside that transaction. Specifically, if an entity is modified
or deleted within a transaction, a query or get returns the original
version of the entity as of the beginning of the transaction, or
nothing if the entity did not exist then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文