英文:
Transactions and entity groups
问题
让我试着描述一下需求。
我的产品有许多站点,每个站点有许多仓库,每个仓库都有一个重要资源的数量,它负责管理。
每当有人需要这个资源时,我希望能够高效地选择一个(站点,仓库)来满足需求(基于一些启发式算法)。
我认为我需要对这样的操作进行事务处理(因为我不希望留下混乱的状态)。
我已经多次阅读了文档,并理解了实体组是执行事务的推荐方式。
根据Google AppEngine Go文档:
一个实体的父实体、父实体的父实体等等递归地称为其祖先;一个实体及其后代被称为属于同一实体组。
如果我让每个仓库都有一个站点作为祖先,那么在操作同一站点下的仓库(即实体组)时,我可以获得良好的控制。
如何以简单的方式使操作在所有站点及其仓库之间安全进行?
我考虑过的方法有:
- 将所有站点都放在一个虚拟父级下,但这样是否允许我以事务方式操作位于站点S1下的仓库W1和位于站点S2下的仓库W2?换句话说,W1和W2是否属于同一实体组,因为它们自己的祖先具有相同的父级?
- 将所有仓库都放在一个虚拟父级下,并做出妥协,因为所有仓库都属于同一实体组。
是我自己的理解有问题,还是根据文档,实体组的含义有些模糊?
附注:所需的安全操作数量相对较低,因此我对将所有内容放在一个实体组下的有限写入吞吐量不太担心。
英文:
Let me try and describe the requirement.
My product has many sites, each sites have many warehouses, and each warehouse has a count of a important resource it is responsible for.
Whenever someone wants that resource, I want to efficiently pick a (site, warehouse) which will fulfill the requirement (based on some heuristics.)
I reckon I need a transaction over such a operation (as I do not want to leave things in a messy state.)
I have gone over the documentation many times and understand that entity groups are the recommended way of doing transactions.
From Google AppEngine Go documentation:
> An entity's parent, parent's parent, and so on recursively, are its ancestors; its children, children's children, and so on, are its descendants. An entity and its descendants are said to belong to the same entity group.
If I make it so that each warehouse has a site as an ancestor, I can get good control when operating on warehouses under the same site (i.e. entity group.)
What is the simple approach of making the operation safe across all sites and their warehouses?
Approaches I have thought of:
- Make all sites under a virtual parent, but does that allow me to operate on W1 (a warehouse under site S1) and W2 (a warehouse under site S2) transactionally? In other words, are W1 and W2 in one entity group because their own ancestors have the same parent?
- Make all warehouses under a virtual parent, and take the compromise as then all the warehouses are in the same entity group.
Is it just me or the meaning of entity group slightly up for interpretation as per the docs?
PS: The number of such safe operations required is relatively low, so I am not too worried about the limited write throughput of having things under one entity group.
答案1
得分: 3
你的问题的答案是肯定的,如果实体具有相同的父实体,即使该父实体对于这些实体中的一个或两个实体来说是祖父级别的,它们仍属于同一组:
每个具有给定根实体作为祖先的实体都属于同一实体组。
来源:Transactions
英文:
The answer to your question is yes, entities belong to the same group if they have the same parent, even if that parent is a grand-parent for one or both of these entities:
> Every entity with a given root entity as an ancestor is in the same
> entity group.
>
> From: Transactions
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论