Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transactions in azure table storage

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?

like image 370
ren Avatar asked Mar 09 '13 09:03

ren


People also ask

What is an Azure storage transaction?

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.

What are entity group transactions?

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.


1 Answers

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.

like image 96
Gaurav Mantri Avatar answered Sep 26 '22 23:09

Gaurav Mantri