简体   繁体   English

如何忽略 ETag 检查

[英]How to ignore ETag checking

My application reads blob content from Azure blob storage.我的应用程序从 Azure blob 存储读取 blob 内容。 The Blob content file is being changed by another program at the same time while it is being read. Blob 内容文件在读取时同时被另一个程序更改。 I get error in the below stream.Read() line.我在下面的 stream.Read() 行中收到错误。 Which I believe is because of mismatch eTag values as file is both read and writen at the same time.我认为这是因为 eTag 值不匹配,因为文件是同时读取和写入的。

How can I make my application ignore checking for ETag value (Which is disabling concurrency check).如何让我的应用程序忽略对 ETag 值的检查(这会禁用并发检查)。 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
   }

Still getting same error.仍然遇到同样的错误。 Sometimes live stream works and displays updated content in UI (Newly written content in the blob are displayed) before this error kicks in. Sometimes error starts at the beginning of streaming itself, even before any chunks are displayed in the UI.有时 live stream 在出现此错误之前工作并在 UI 中显示更新的内容(显示 blob 中新写入的内容)。有时错误开始于流本身的开始,甚至在 UI 中显示任何块之前。 There is no concrete pattern.没有具体的模式。

Read() error below:下面的 Read() 错误:

Azure.RequestFailedException: The condition specified using HTTP conditional header(s) is not met.
RequestId:b84cc30f-501e-009f-4596-295240000000
Time:2023-01-16T10:37:49.1672314Z
Status: 412 (The condition specified using HTTP conditional header(s) is not met.)
ErrorCode: ConditionNotMet

Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>ConditionNotMet</Code><Message>The condition specified using HTTP conditional header(s) is not met.
RequestId:b84cc30f-501e-009f-4596-2952400000
Time:2023-01-16T10:37:49.1672314Z</Message></Error>

Headers:
Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id: b84cc30f-501e-009f-4596-29524000000
x-ms-client-request-id: 70f94258-163a-464c-879f-437d5ac7be7
x-ms-version: 2021-10-04
x-ms-error-code: ConditionNotMet
Date: Mon, 16 Jan 2023 10:37:48 GMT
Content-Length: 252
Content-Type: application/xml

   at Azure.Storage.Blobs.BlobRestClient.Download(String snapshot, String versionId, Nullable`1 timeout, String range, String leaseId, Nullable`1 rangeGetContentMD5, Nullable`1 rangeGetContentCRC64, String encryptionKey, String encryptionKeySha256, Nullable`1 encryptionAlgorithm, Nullable`1 ifModifiedSince, Nullable`1 ifUnmodifiedSince, String ifMatch, String ifNoneMatch, String ifTags, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.Specialized.BlobBaseClient.StartDownloadAsync(HttpRange range, BlobRequestConditions conditions, DownloadTransferValidationOptions validationOptions, Int64 startOffset, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.Specialized.BlobBaseClient.DownloadStreamingInternal(HttpRange range, BlobRequestConditions conditions, DownloadTransferValidationOptions transferValidationOverride, IProgress`1 progressHandler, String operationName, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.Specialized.BlobBaseClient.<>c__DisplayClass97_0.<<OpenReadInternal>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Azure.Storage.LazyLoadingReadOnlyStream`1.DownloadInternal(Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.LazyLoadingReadOnlyStream`1.ReadInternal(Byte[] buffer, Int32 offset, Int32 count, Boolean async, CancellationToken cancellationToken)
   at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](Task`1 task)
   at Azure.Storage.LazyLoadingReadOnlyStream`1.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Project.Server.Models.ItemRepository.GetFile(String fileName, Int64 offset, Int64 blobLengthRemaining, Int64 prevContentLen) in C:\Users\Project\Server\Models\ItemRepository.cs:line 221
   at LogViewer.Server.Controllers.ItemController.GetBlobFile(String fileName, Int64 offset, Int64 blobLengthRemaining, Int64 contentLen) in C:\Users\Project\Server\Controllers\ItemController.cs:line 60
   at lambda_method60(Closure , Object )

..... .....

Thank you.谢谢你。

If you dont pass the blobRequestConditions to the method, it will disable the concurrency check如果您不将 blobRequestConditions 传递给该方法,它将禁用并发检查

using (var stream = await blob.OpenReadAsync(offset, segmentSize)) 
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;
                 }   
         }
 }
  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM