Azure Table 存储 - 管理并发

Azure Table Storage - Managing Concurrency

我阅读了这篇关于 Microsoft Azure 存储中并发性的在线文章,特别是 Table 存储。 https://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/

说明Table存储会默认采用乐观并发策略。电子标签的使用是实施该战略的关键。例如,Replace 操作需要 E-Tag 的 If-Match,并且在服务响应中总是 return E-Tag。因此,如果我想使用 Replace 操作,我必须确保我发送的实体具有 E-Tag 值。这对设计有影响。例如,从我的数据记录实体中抽象我的应用程序域实体时我必须小心,因为层之间的映射将丢失 E-Tag 上下文,除非我引入 E-Tag 的概念可能作为更广泛应用程序的相关 ID对我的域实体通用。所以这不是问题。问题是我对 InsertOrReplace 操作感到困惑。它不需要 If-Match。当操作执行替换时,这怎么可能?另外,这对并发管理有何影响?这是否意味着特定于 InsertOrReplace 操作,Table服务将改为默认为最后写入者获胜策略?

是的,Azure 存储 Table 服务将接受 InsertOrReplace 操作的每个最后写入者获胜策略的请求。

The Insert Or Replace Entity operation does not use the If-Match header and it must be called using the 2011-08-18 version or newer. These attributes distinguish this operation from the Update Entity operation. If the Insert Or Replace Entity operation is used to replace an entity, any properties from the previous entity will be removed if the new entity does not define them. Properties with a null value will also be removed.

如果您也希望 Replace 操作的 last writer 获胜策略,请将 ETag 设置为“*”。

To force an unconditional update operation, set the value of the If-Match header to the wildcard character (*) on the request. Passing this value to the operation will override the default optimistic concurrency and ignore any mismatch in ETag values.