我想發送一個簡單批量的插入操作到Azure表存儲,但似乎整個批處理事務失效,並且使用託管的azure存儲客戶端如果批處理中有單個插入到預先存在的記錄,則ExecuteBatch方法本身會引發異常。 (使用2.0客戶端):通過使用InsertOrMerge避免Azure表存儲批量插入與潛在預先存在的行鍵
public class SampleEntity : TableEntity
{
public SampleEntity(string partKey, string rowKey)
{
this.PartitionKey = partKey;
this.RowKey = rowKey;
}
}
var acct = CloudStorageAccount.DevelopmentStorageAccount;
var client = acct.CreateCloudTableClient();
var table = client.GetTableReference("SampleEntities");
var foo = new SampleEntity("partition1", "preexistingKey");
var bar = new SampleEntity("partition1", "newKey");
var batchOp = new TableBatchOperation();
batchOp.Add(TableOperation.Insert(foo));
batchOp.Add(TableOperation.Insert(bar));
var result = table.ExecuteBatch(batchOp); // throws exception: "0:The specified entity already exists."
將批料級異常但隨後各個操作響應返回204,該特定操作是否插入或合併它。因此,客戶端應用程序似乎不可能保留關於它或羣集中的其他節點是否插入記錄的知識。不幸的是,在我目前的情況下,這種知識對於一些下游同步是必需的。
是否有一些配置或技術允許批處理插入繼續並返回每個項目的特定響應代碼而不拋出一個全局異常?