Suppose I have:
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);
}
What I want is this: if insert fails, delete should be undone. Is this correct way of making transaction? Everything happens in same partition/table. Also what are other limitations of transactions, I've read somewhere that no more than 4 Mb could be stored within transaction, is this still correct?
Transaction Charges: You essentially interact with Windows Azure Storage using REST API. A transaction is defined as a single API call. For example, if you upload a file and the file is uploaded in single shot (i.e. without breaking it into chunks or blocks), that's one transaction.
Entity Group transaction is similar to the atomic transaction concept in SQL Server. Entity Group transaction can be performed on a single partition. With this feature we can perform multiple CRUD operations on entities within a single partition in a single batch operation.
Assuming all the entities on which operations need to be performed have the same PartitionKey, you can make use of Entity Group Transaction
functionality available in Windows Azure Table Storage. It does exactly that. If an operation on an entity in a transaction fails, the whole transaction is rolled back.
However it seems that you're deleting an entity and creating the same entity again. That scenario will not work in an entity batch transaction as an entity can appear only once in a transaction and only one operation can be performed on an entity. It looks like what you're interested in is replacing an entity. In that case, you can directly use InsertOrReplace()
functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With