GAE多租户和事务 – Go

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

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

两个需要注意的事项:

  1. 命名空间是实体键的一部分,因此事务仅适用于作为事务一部分的实体。即使其他命名空间的实体具有相同的ID,它们也不会受到影响。

  2. GAE上的事务不会进行锁定,而是使用乐观并发控制。因此,事务永远不会阻塞,只有当两个事务操作相同的实体时,第二个事务会失败,然后运行时会尝试最多三次重复。这种自动重试是为什么您的事务应该是幂等的(即多次运行代码应该产生相同的最终结果)的原因。

英文:

Two things to note:

  1. 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.

  2. 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

huangapple
  • 本文由 发表于 2013年11月25日 14:15:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/20185920.html
匿名

发表评论

匿名网友

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

确定