Sharing data between appengine modules

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

Sharing data between appengine modules

问题

我正在尝试使用App Engine Datastore在App Engine模块之间共享一个键。我在一个模块中写入了该键,可以从该模块中读取它。

但是,尝试从第二个模块中读取它时却不起作用,并且返回了"no such entity"的响应。

在模块之间共享键的最佳方法是什么?我可以使用Datastore来实现吗?根据我在文档中阅读的内容,Datastore是在服务之间共享的,但对我来说似乎不起作用。

英文:

I'm trying to use appengine datastore to share a key between appengine modules.
I'm writing the key in one module, I can read it from that module.

Trying to read it from the second module doesn't work, and I get no such entity response.

What's the best way to share a key between modules? can I use datastore for that? from what I have read in the documentation data store is shared between services. but it doesn't seems to work for me.

答案1

得分: 1

您可能遇到了一些最终一致性的问题。Datastore是分布式的,所以一个服务可能会访问到数据的一个一致版本,而另一个服务(模块)可能会访问到一个过期的版本。Datastore绝对是在模块之间共享数据的一种方式,所以可能存在一致性问题,除非您重新组织数据或查询以实现强一致性,否则不能保证能够立即读取数据,或者可能存在其他问题,比如在其他模块中使用了错误的键或者访问了不同的命名空间。

以下是一些关于Datastore一致性的资源:

从最后一个链接中可以得到以下信息:
如果您需要查询的强一致性,请使用祖先查询(使用祖先查询之前,您需要为强一致性进行数据结构化)。祖先查询返回强一致性的结果。请注意,非祖先的仅键查询后跟lookup()不会返回强结果,因为非祖先的仅键查询可能从在查询时不一致的索引中获取结果。

英文:

There are eventual consistency issues you may be hitting. Datastore is distributed so it's possible one service hits a consistent version of the data and another service(module) hits another version that is stale. The datastore is definitely a way to share data between modules so it could either be a consistency problem where you won't be guaranteed to be able to read the data back right away unless you restructure your data or your query to be strongly consistent, or it could be some other problem like you have the wrong key in the other module or are somehow hitting a different namespace.

Here are a some resources on datastore consistency:
https://cloud.google.com/datastore/docs/concepts/structuring_for_strong_consistency
https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/
https://cloud.google.com/datastore/docs/best-practices

From the last link:

> If you need strong consistency for your queries, use an ancestor
> query. (To use ancestor queries, you first need to structure your data
> for strong consistency.) An ancestor query returns strongly consistent
> results. Note that a non-ancestor keys-only query followed by a
> lookup() does not return strong results, because the non-ancestor
> keys-only query could get results from an index that is not consistent
> at the time of the query.

huangapple
  • 本文由 发表于 2017年5月6日 22:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/43821899.html
匿名

发表评论

匿名网友

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

确定