Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete azure table storage row without checking for existence

I've been using azure table storage for years, and I'm not sure what the "proper" way to do this is with the newest WindowsAzure.Storage library, version 5.0.1-preview (for use in a new ASP.NET 5 application):

Problem: Given a partition key and row key, delete the row without checking for existence first, and without failing if it does not exist.

Current Solution: This code works... but the exception handling is confusing:

public async Task DeleteRowAsync(CloudTable table, string partition, string row)
{
    var entity = new DynamicTableEntity(partition, row);
    entity.ETag = "*";

    var op = TableOperation.Delete(entity);
    try
    {
        await table.ExecuteAsync(op);
    }
    catch (Exception ex)
    {
        var result = RequestResult.TranslateFromExceptionMessage(ex.Message);
        if (result == null || result.HttpStatusCode != 404)
            throw ex;
    }
}

Questions:

  1. The exception itself pointed me to this TranslateFromExceptionMessage method... I can't find a whole lot of information on that and WrappedStorageException (the type of the exception that is thrown). Is this some kind of new/preferred way to check for 404 errors on storage exceptions? Does anyone know if all storage exceptions will now use this, or do I need to write code to test and figure it out?

  2. There is an InnerException of type StorageException. Presumably our older code that used StorageException.RequestInformation.HttpStatusCode could access this inner exception in the same way. Is that "OK", or is parsing these new XML error messages better or more robust somehow?

  3. Is there a different approach altogether that I should be considering for this case?

like image 919
Yellowfive Avatar asked Aug 31 '15 21:08

Yellowfive


People also ask

How do you delete a column in Azure Table storage?

you can do the same by using azure storage explorer. You can export the table of choice, delete the property in the CSV file and import it back in new table. drop the existing table and rename the new table to the existing one. This is kind of a work around.

What is RowKey in Azure Table storage?

The row key is a unique identifier for an entity within a given partition. Together the PartitionKey and RowKey uniquely identify every entity within a table. The row key is a string value that may be up to 1 KiB in size. You must include the RowKey property in every insert, update, and delete operation.

Is Azure table storage persistent?

Azure Blob Storage Tiers The blob storage option is not persistent, as opposed to other Azure storage options like hard disks of Infrastructure-as-a-Service (IAAS) or VMs. As a result, you have to use persistent stores like tiers for long-term storage of files. There are three types of storage tiers.


1 Answers

The RequestResult.TranslateFromExceptionMessage method is now marked [Obsolete] and I wanted a way to ignore 404's myself.

Based on your tip to check out the RequestInformation.HttpStatusCode I came up with the following:

try
{
    await table.ExecuteAsync(op);
}
catch (StorageException storEx)
{
    if (storEx.RequestInformation.HttpStatusCode != 404)
    {
        throw;
    }
}

like image 70
dana Avatar answered Oct 03 '22 11:10

dana