azure - Azure 表存储中的事务

标签 azure azure-table-storage

假设我有:

using (TransactionScope scope = new TransactionScope()) 
{
    if (IndexExists(index.RowKey))
        DeleteIndex(index.RowKey); //deletes using TableOperation.Delete

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
    CloudTable table = tableClient.GetTableReference(Const.IndexTable);

    TableOperation insertOperation = TableOperation.Insert(index);
    table.Execute(insertOperation);   
}

我想要的是:如果插入失败,删除应该被撤消。这是正确的交易方式吗?一切都发生在同一个分区/表中。另外,事务的其他限制是什么,我在某处读到事务中不能存储超过 4 Mb,这仍然正确吗?

最佳答案

假设所有需要操作的实体都有相同的PartitionKey,则可以使用 Entity Group Transaction Windows Azure 表存储中提供的功能。它正是这样做的。如果事务中对实体的操作失败,则整个事务将回滚。

但是,您似乎正在删除一个实体并再次创建相同的实体。该场景在实体批量事务中不起作用,因为实体在事务中只能出现一次,并且只能对实体执行一个操作。看来您感兴趣的是替换实体。这种情况下,您可以直接使用 InsertOrReplace()功能。

关于azure - Azure 表存储中的事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15309294/

相关文章:

java - 如何检测Dataverse表记录的变化

Azure DevOps 2020 本地重命名 Wiki

azure - 将链接数据添加到 Azure 表中

c# - Azure表存储(分区键行键),如何插入对应于相同分区和不同rowKey的多个实体?

linux - 使用 Azure Linux 诊断进行监控

azure - 使用 Pulumi 将现有 VNet 添加到 Azure KeyVault 失败

azure - AddAzureKeyVault 在 dotnet core 应用程序启动期间引入延迟,至少 15 秒延迟

c# - Azure 表存储 sdk 1.6 Upsert 未插入

c# - 客户端存储库 2.0 中对 AsTableServiceQuery() 的更改

Azure 流分析将 int64 输出为 int32