I have this code for deleting some items:
private static void DeleteBatch(IList<TableEntity> toDelete)
{
if(toDelete == null)
throw new ArgumentNullException("toDelete");
if(toDelete.Count == 0)
throw new ArgumentException("There is no elements in toDelete.");
if(toDelete.GroupBy(e => e.PartitionKey).Count() > 1)
throw new ArgumentException("The entities to delete must have the same PartitionKey.");
Parallel.ForEach(Partitioner.Create(0, toDelete.Count, 100),
range =>
{
TableBatchOperation batchOperation = new TableBatchOperation();
for (Int32 i = range.Item1; i < range.Item2; i++)
batchOperation.Delete(toDelete[i]);
_table.ExecuteBatch(batchOperation);
});
}
The table entities are passed with a * ETag.
Sometimes this will throw a StorageException: The specified resource does not exist.
I presume this is a 404 HttpStatusCode. In this case I don't care whether it does not exist, so I want to ignore this exception for the operations that caused them. How can I ignore 404 for invididual TableOperations in the batch, or at least retry the batch operation for TableOperations that did not throw this exception (how do I know which operations failed). It feels very ineffective to do each operation individually just to be able to find which caused 404.
In a batch operation, I don't think it's possible to ignore errors. There's one thing you could do to identify which entity in the batch failed and that can be done by capturing StorageException and inspecting RequestInformation.ExtendedErrorInformation property. Take a look at the screenshot below especially for ErrorCode and ErrorMessage. What I have done here is made 2nd entity in my batch fail in a delete entity batch operation. You'll get ErrorCode as "ResourceNotFound" but what's interesting is ErrorMessage. If you see, you get ErrorMessage as "1:The specified resource does not exist". It basically gives you the index of the entity which failed in the batch.
What you could do then is split the batch in 3 parts - ones before this failed entity, this failed entity (single item) and then entities after this failed entity and try them in separate operations.
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