简体   繁体   English

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

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

I have method that submits batch transaction to table storage (Nuget: Azure.Data.Tables - 12.6.1).我有将批处理事务提交到表存储的方法(Nuget:Azure.Data.Tables - 12.6.1)。
Code below:下面的代码:

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?
        }
    }
}

This will call SubmitTransactionAsync with up to hundred TableTransactionActions.这将使用多达一百个 TableTransactionAction 调用 SubmitTransactionAsync。 But will the submitted batch transaction count as one "batch write operation behind the scenes or will it actually be 100 different ones?但是提交的批量事务会算作一个“幕后的批量写入操作”还是实际上是 100 个不同的操作?

Batch write operation is three times more costly than normal write operation, but if behind the scenes hundred entities will be uploaded as one batch write operation than I'm a happy man;)批量写操作的成本是普通写操作的三倍,但如果在幕后将一百个实体作为一个批量写操作上传,那我是一个快乐的人;)
Azure Table Storage Pricing Azure 表存储定价

Really would appreciate if somebody smarter can clarify this!如果有更聪明的人能澄清这一点,我将不胜感激!

You can read more about it from the docs page.您可以从文档页面了解更多信息。 https://docs.microsoft.com/en-us/rest/api/storageservices/performing-entity-group-transactions https://docs.microsoft.com/en-us/rest/api/storageservices/performing-entity-group-transactions

From the docs:从文档:

Operations within a change set are processed atomically;变更集中的操作是原子处理的; that is, all operations in the change set either succeed or fail.也就是说,更改集中的所有操作要么成功,要么失败。 Operations are processed in the order they are specified in the change set.操作按照它们在更改集中指定的顺序进行处理。

Because you can only update one partition at a time, I am assuming they do something to make it less than 100 different operations, but they don't specify how it is implemented on the backend.因为一次只能更新一个分区,我假设他们做了一些事情以使其少于 100 个不同的操作,但他们没有指定它是如何在后端实现的。 The important thing is you can treat it as one operation and know that all operations either succeeded or failed;重要的是你可以把它当作一个操作,并且知道所有操作要么成功要么失败; you won't end up with a partially applied transaction.您最终不会得到部分应用的交易。

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

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