跨多个名称空间的数据存储区索引是否相同? [英] Are datastore indexes same across multiple namespaces?
问题描述
我正在开发多租户SaaS系统,并将所有数据存储在Datastore中.对于每个客户端,我都有一个单独的名称空间,但是在所有名称空间中,都具有相同的种类"集.
I'm working on developing a multi-tenant SaaS system and I'm storing all the data in Datastore. I have a separate namespace for every client, but the same set of "kinds" in all namespaces.
这是我的问题:如果我为一种实体类型构建自定义索引,那么该索引是否可以在所有命名空间中使用?还是应该在某个地方指定名称空间?
This is my question: If I build custom index for one entity kind, will this index be served across all namespaces? or should I specify the namespace also somewhere?
这是我的自定义索引之一:
This is one of my custom indices:
- kind: loginTrack
ancestor: no
properties:
- name: logDate
- name: username
- name: timeStamp
我将其部署为数据存储区中的自定义索引,但是不确定它是否适用于所有名称空间.
I deployed this as a custom index in Datastore, but I'm not sure if it works for all namespaces.
数据存储区如何处理开发者提供的索引?
How does Datastore handle developer-supplied-index?
推荐答案
如您所见,索引本身没有空间容纳名称空间信息,它在应用程序域内的所有名称空间中的运行方式相同.
The index itself, as you observed, has no room for namespace information, it operates the same way across all namespaces inside an app's domain.
区别在于映射到每个名称空间的数据存储分区.来自多租户和分区数据(重点是我):
What's different is the datastore partition mapped to each namespace. From Multitenancy and partitioned data (emphasis mine):
Cloud Datastore使用分区为每个租户隔离数据.这 项目ID 和名称空间ID的组合形成一个分区ID, 标识每个分区.一个实体属于一个 分区,并且查询的作用域仅限于单个分区.
Cloud Datastore uses partitions to silo data for each tenant. The combination of a project ID and a namespace ID forms a partition ID, which identifies each partition. An entity belongs to a single partition, and queries are scoped to a single partition.
但是请注意,对特定承租人的数据进行操作是您应用程序的责任:与特定承租人相关的所有操作必须在该承租人的分区/命名空间上下文中执行(即必须将名称空间指定为与数据存储区相关的调用的参数.
But note that operating on a certain tenant's data is your app's responsability: all operations related to a certain tenant must be executed in that tenant's partition/namespace context (i.e. the namespace must be specified as argument to the datastore-related calls).
对于在租户的域中使用(共享)索引的特定情况,您在构建查询时必须指定租户的名称空间.否则,您将无法从该租户的分区中获得结果.
For the particular case of using the (shared) index in a tenant's domain you have to specify the tenant's namespace when building the query. Otherwise you won't get the results from that tenant's partition.
这篇关于跨多个名称空间的数据存储区索引是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!