App Engine 中的多租户如何与 Objectify 配合使用?
应用程序引擎中命名空间的多租户如何工作? 我的应用程序有多个用户,每个用户都有点像多租户中的租户。 他们的 URL 以domain/customer/companyToken#pageName?param1¶m2 开头。 因此,从 Google 文档来看,如果我想为每个客户应用带有命名空间的多租户 您需要为每个客户分配一个唯一的 NamespaceManager id 如下所示:
NamespaceManager.set(request.getServerName());
现在我有几个问题。
App Engine 命名空间的多租户实际如何工作?
它如何改变我们访问数据的一般方式?
它如何改变我们使用 Objectify 访问数据的方式?
首先,我对将上述应用到应用程序的理解是,在检索数据时,与上述客户(租户)相关的所有数据都聚集在同一名称空间中,那么我们如何使用 Objectify 访问数据的方式发生变化?目前,公司 obj 充当与客户相关的所有 obj 的父级。 (那么在我的应用程序中?)
提前非常感谢您。
How does multi-tenancy with namespaces in app engine works?
My application has multiple users and each users are sort of like tenants in multi-tenancy.
Their URL starts with domain/customer/companyToken#pageName?param1¶m2.
So from the Google docs if I want to apply a multi-tenancy with namespace with each customers
you need to assign a unique ids for NamespaceManager to each customers
So something like below:
NamespaceManager.set(request.getServerName());
Now I have a few questions.
How does the multi-tenancy with Namespace for the App Engine really work?
How does it change the way we access data in general?
How does it change the way we access data using Objectify?
First my understanding of applying above to the application is that when retrieving the data all the data related to above customers(tenants) are gathered together in the same namespace, so how does the way we access data change using the Objectify? Currently Company obj serves as parent of all the obj related to customers. (So in case of my application?)
Thank you so much in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google AppEngine 不是开源的,因此只有 Google 真正知道其内部工作原理。但有一些关于数据存储区内部构建方式的公开数据:http://www.youtube。 com/watch?v=tx5gdoNpcZM。基本上,所有 AppEngine 数据都位于分布在多台计算机上的一张表中(是的,一张表适用于所有 AppEngine 应用程序)。每个实体都有唯一标识它的键(id、父级,您可以在应用程序中看到),但还有一个数据可以告诉实体属于哪个应用程序。该数据是 AppEngine 内部的,用户看不到它。我的猜测是,这部分也扩展为包含命名空间数据。
事实并非如此。数据存储 API 具有命名空间感知能力,因此您的所有代码都保持不变。它在内部知道实体属于哪个命名空间。
Objectify 构建在低级 Datastore API 之上,因此答案与 2 相同。
命名空间划分数据:设置命名空间后,Datastore API 将仅看到在此命名空间下添加的实体。
Google AppEngine is not open-source so only Google really know how this works internally. But there is some publicly-available data about how datastore is built internally: http://www.youtube.com/watch?v=tx5gdoNpcZM. Basically all AppEngine data is in one table (yes one table for ALL AppEngine applications) distributed across multiple computers. Every entity has Key by which it is uniquely identified (id, parent, which you can see in your app), but there is also a data that tells to which app an Entity belongs. This data is AppEngine internal and user does not see it. My guess is that this part is also extended to include namespace data.
It doesn't. Datastore API is namespace-aware so all you code stays the same. It internally knows to which namespace an Entity belongs.
Objectify is built on top of low-level Datastore API, so answer is the same as 2.
Namespaces compartmentalizes data: once you set a namespace, Datastore API will only see Entities that were added under this namespace.
在数据存储的存储级别,命名空间就像应用程序 ID。每个命名空间本质上都将数据存储区视为应用程序数据的另一个视图。这就是为什么像查询这样的操作不能跨越命名空间(至少现在是这样)。每个命名空间甚至 ID 范围也不同。
您需要了解您真正使用的名称空间。例如,一旦创建了实体,它的名称空间就不会更改,因此执行 NamespaceManager.set(...) 将对其键没有影响。与查询对象类似。创建查询后,就会设置其名称空间。与 MemcacheService 相同。因此,如果您习惯于调用 NamespaceManager.set 而不是从请求开始时调用,那么了解哪些对象具有哪些命名空间就很重要。
很难了解 Obectify 如何使用数据存储区 API,因此在一个请求中多次更改当前命名空间需要了解 Objectify 如何使用数据存储区 API,以确保您不会无意中在非预期的命名空间中创建实体.
一般来说,您需要知道 Objectify 何时创建低级 Key、Entity 和 Query 对象,并确保当前命名空间设置为您想要的命名空间。如果每个请求只有一个命名空间,那就很容易了。
At the storage levels of datastore, namespace is just like an app-id. Each namespace essentially looks to the datastore as another view into the app's data. This is why operations like query cannot span namespaces (at least for now). Even id ranges are different per namespace.
You need to be aware of which namespace you're really using. e.g. Once an entity is created, it's namespace does not change, so doing a NamespaceManager.set(...) will have no effect on its key. Similarly with a Query object. Once a query is created, its namespace is set. Same with MemcacheService. Hence it's important to know which objects have which namespaces if you're in the habbit of calling NamespaceManager.set more than from the beginning of the request.
It's hard to know how Obectify uses the datastore API, so changing the current namespace multiple times in one request needs to be done with the knowledge of how Objectify uses the datastore API to ensure you don't inadvertently create entities in unintended namespaces.
In general, you meed to know when Objectify creates the low level Key, Entity and Query objects and make sure that the current namespace is set to the namespace you intend. It's easy if there is ever only one namespace per request.