并发在 Azure table 存储中不起作用

Concurrency not working in Azure table storage

在使用 Azure Table 存储时,我遇到了多线程并发问题。每个线程都试图更新相同的记录(分区键 + 行键)。在那种情况下,我的期望是如果它是陈旧数据,库将自动检查 etag 并抛出异常 412 Pre-Condition Failed。但是,在我的情况下,它总是随着最后一次调用而更新。

值得注意的是,如果我使用TableEntityOperation.Replace(entity),它会抛出 412 异常。 TableEntityOperation.InsertorMerge(entity) 似乎没有检查并发性。

您看到此行为的原因是因为 TableEntityOperation.InsertorMerge(entity) 方法,它是 Insert Or Merge Entity REST API operation does not support optimistic concurrency. Only Merge Entity and Update Entity 的包装器,支持开放式并发。

来自 documentation(强调我的):

The Insert Or Merge Entity operation uses the MERGE verb and must be called using the 2011-08-18 version or newer. In addition, it does not use the If-Match header. These attributes distinguish this operation from the Update Entity operation, though the request body is the same for both operations.