繁体   English   中英

Azure 表存储,帮我弄清楚批量操作的幕后发生了什么

[英]Azure table storage, help me clarify what's happening behind the scenes in batch operation

我有将批处理事务提交到表存储的方法(Nuget:Azure.Data.Tables - 12.6.1)。
下面的代码:

private static async Task BatchManipulateEntities<T>(TableClient tableClient, IEnumerable<T> entities, TableTransactionActionType tableTransactionActionType, int batchSize) where T : class, ITableEntity, new()
{
    var groups = entities.GroupBy(x => new { x.PartitionKey });
    foreach (var group in groups)
    {
        var items = group.AsEnumerable();
        while (items.Any())
        {
            var batch = items.Take(batchSize);
            items = items.Skip(batchSize);

            var actions = batch.Select(e => new TableTransactionAction(tableTransactionActionType, e)).ToList();
            await tableClient.SubmitTransactionAsync(actions); // <-- Will this count as one batch write operation?
        }
    }
}

这将使用多达一百个 TableTransactionAction 调用 SubmitTransactionAsync。 但是提交的批量事务会算作一个“幕后的批量写入操作”还是实际上是 100 个不同的操作?

批量写操作的成本是普通写操作的三倍,但如果在幕后将一百个实体作为一个批量写操作上传,那我是一个快乐的人;)
Azure 表存储定价

如果有更聪明的人能澄清这一点,我将不胜感激!

您可以从文档页面了解更多信息。 https://docs.microsoft.com/en-us/rest/api/storageservices/performing-entity-group-transactions

从文档:

变更集中的操作是原子处理的; 也就是说,更改集中的所有操作要么成功,要么失败。 操作按照它们在更改集中指定的顺序进行处理。

因为一次只能更新一个分区,我假设他们做了一些事情以使其少于 100 个不同的操作,但他们没有指定它是如何在后端实现的。 重要的是你可以把它当作一个操作,并且知道所有操作要么成功要么失败; 您最终不会得到部分应用的交易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM