Sarahrb
Sarahrb

Reputation: 669

How to ignore ETag checking

My application reads blob content from Azure blob storage. The Blob content file is being changed by another program at the same time while it is being read. I get error in the Read() line. Which I believe is because of mismatch eTag values as file is both read and written at the same time.

How can I make my application ignore checking for ETag value (Which is disabling concurrency check). Tried as below. But same error.

    BlobRequestConditions blobRequestConditions = new BlobRequestConditions
    {
           IfMatch = new ETag("*")
           //IfMatch = ETag.All
    };

   using (var stream = await blob.OpenReadAsync(offset, sgmtSize, blobRequestConditions)) 
   {
      
        stream.Read(); // ERROR in this line
   }

Read() error below:

Azure.RequestFailedException: The condition specified using HTTP conditional header(s) is not met.
RequestId:0000000
Time:2022-05-16T10:37:49.1672314Z
Status: 412 (The condition specified using HTTP conditional header(s) is not met.)
ErrorCode: ConditionNotMet

Upvotes: 2

Views: 2870

Answers (2)

Sarahrb
Sarahrb

Reputation: 669

BlobProperties properties1 = await blob.GetPropertiesAsync();
string originalETag = properties.ETag;
bool retry = true;
while (retry)
{    

      try{ 
    
            BlobRequestConditions blobRequestConditions = new BlobRequestConditions
            {
                  IfMatch = new ETag(originalETag)
            };
        
            using (var stream = await blob.OpenReadAsync(offset, segmentSize, blobRequestConditions)) 
            retry = false;

        }
        catch(RequestFailedException ex){
               if (ex.ErrorCode == "ConditionNotMet")
                {
                     retry = true;
                }
                       
                else
                {
                    System.Diagnostics.Debug.WriteLine("Failed to Read");
                    throw;
                 }   
         }
 }
  

Upvotes: 1

Jonxag
Jonxag

Reputation: 787

If you dont pass the blobRequestConditions to the method, it will disable the concurrency check

using (var stream = await blob.OpenReadAsync(offset, segmentSize)) 

Upvotes: 1

Related Questions