英文:
GAE Multitenancy and Transaction - Go
问题
如果我在GAE Datastore上使用多租户功能,是否每个租户都会应用一个数据存储事务锁?或者如果一个租户正在使用数据存储事务,所有其他租户是否都必须等待,直到该租户的事务完成?
英文:
If I use multitenancy feature on GAE Datastore, will a datastore transaction lock be applied per tenant as well? Or if a tenant is using a datastore transaction, all of the other tenants will have to wait until the tenant's transaction is finished?
答案1
得分: 2
两个需要注意的事项:
-
命名空间是实体键的一部分,因此事务仅适用于作为事务一部分的实体。即使其他命名空间的实体具有相同的ID,它们也不会受到影响。
-
GAE上的事务不会进行锁定,而是使用乐观并发控制。因此,事务永远不会阻塞,只有当两个事务操作相同的实体时,第二个事务会失败,然后运行时会尝试最多三次重复。这种自动重试是为什么您的事务应该是幂等的(即多次运行代码应该产生相同的最终结果)的原因。
英文:
Two things to note:
-
Namespace is part of the key of the entity, so transaction will work only for entities that are part of your transaction. Entities of other namespaces will not be affected even if they have same IDs.
-
Transactions on GAE do not do locking, instead they use optimistic concurrency control. So transactions are never blocking, just when two transactions operate on same entities the second will fail and then go runtime will try to repeat it up to three times. This auto-retry is the reason why your transactions should be idempotent (= running the code multiple times should produce same end result).
答案2
得分: 1
交易的范围仅限于实体组。命名空间(多租户)本身不定义实体组。您需要键(加上可能的祖先)。
唯一的冲突可能发生在多个请求同时写入同一实体组的情况下。在使用命名空间的情况下,租户之间不会发生这种情况。
https://developers.google.com/appengine/docs/go/datastore/entities#Go_Ancestor_paths
英文:
The scope of transactions is limited to entity groups. Namespaces (multi tenancy) don't define an entity group on their own. You need the key (plus potential ancestor).
The only clash will be with multiple requests writing to the same entity group. With namespaces in use that could not happen between tenants.
https://developers.google.com/appengine/docs/go/datastore/entities#Go_Ancestor_paths
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论