【问题标题】:Why am I getting "The append position condition specified was not met" from CloudAppendBlob.AppendTextAsync?为什么我从 CloudAppendBlob.AppendTextAsync 收到“未满足指定的附加位置条件”?
【发布时间】:2018-04-26 14:17:42
【问题描述】:

我在使用 CloudAppendBlob.AppendTextAsync 实现的 Logger 组件中收到“未满足指定的附加位置条件”。我已经搜索并看到如果您从多个任务中使用 AppendTextAsync 可能会出现问题,但我没有在我的代码中这样做。我正在使用 ConcurrentQueue 来记录消息,它是从队列中读取的单个任务,它调用 AppendTextAsync。

这是我的代码:

private async Task MessageLogger()
{
    string messages = "";
    while (true)
    {
        // Check if a new log file should be created
        if (DateTime.UtcNow.Day != _logCreatedUtc.Day)
        {
            // Create a new log file
            await CreateNewLogAsync();
        }

        if (_messageQueue.Count == 0 && messages.Length == 0)
        {
            // No messages to write, wait
            await Task.Delay(50);
            continue;
        }

        int n = 0;
        while ((this._messageQueue.Count > 0) && (n < 50))
        {
            string message;
            if (this._messageQueue.TryDequeue(out message))
            {
                messages += message;
                n++;
            }
        }

        try
        {
            // Append messages to Azure Blob
            await _appendBlob.AppendTextAsync(messages);
            messages = "";
        }
        catch (Microsoft.WindowsAzure.Storage.StorageException se)
            when(se.RequestInformation.HttpStatusCode == 404)
        {
            LogException("StorageException from CloudAppendBlob.AppendTextAsync", se);
            // Log file was deleted. Create a new log file
            await CreateNewLogAsync();
        }
        catch (AggregateException ex)
        {
            LogException("AggregateException from CloudAppendBlob.AppendTextAsync", ex);
            StorageException se = ExtractStorageException(ex);
            if (se != null && se.RequestInformation.ExtendedErrorInformation != null)
            {
                if (se.RequestInformation.ExtendedErrorInformation.ErrorCode == "BlockCountExceedsLimit")
                    // Block count exceeds limit. Create a new log file
                    await CreateNewLogAsync();
            }
        }
        catch (Exception ex)
        {
            LogException("Exception from CloudAppendBlob.AppendTextAsync", ex);
            await Task.Delay(1000);
        }
    }
}

这是一个生成的示例日志文件:

19.04.2018 00:00:00.115 - INFO: Logfile created: 2018_04_19/SensorDataProcessor_2018_04_19_0000.log
19.04.2018 00:00:00.116 - INFO: LogLevel is currently set to Information
19.04.2018 00:00:00.136 - INFO: Logfile created: 2018_04_19/SensorDataProcessor_2018_04_19_0000.log
19.04.2018 00:00:00.137 - INFO: LogLevel is currently set to Information
19.04.2018 00:00:00.364 - <<EXCEPTION>>: AggregateException from CloudAppendBlob.AppendTextAsync
19.04.2018 00:00:00.365 - <<EXCEPTION>>: Type =<System.AggregateException> Message =<One or more errors occurred. (One or more errors occurred. (The append position condition specified was not met.))> InnerException.Message=<One or more errors occurred. (The append position condition specified was not met.)>
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.<Dispose>b__8_0()
   at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.RunWithoutSynchronizationContext(Action actionToRun)
   at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at Microsoft.WindowsAzure.Storage.Blob.CloudAppendBlob.<UploadFromStreamAsyncHelper>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Infrastructure.Logging.AzureBlob.Logger.<MessageLogger>d__24.MoveNext() in /opt/vsts/work/1/s/Infrastructure/Logging/Infrastructure.Logging.AzureBlob/Logger.cs:line 183
19.04.2018 00:00:01.434 - INFO: Processed SensorData: Id=1005004 Timestamp=19.04.2018 00:00:00.684 Value=259.2 ElapsedTime=566
19.04.2018 00:00:02.348 - INFO: Processed SensorData: Id=1005004 Timestamp=19.04.2018 00:00:01.688 Value=532.9 ElapsedTime=444
19.04.2018 00:00:05.643 - INFO: Processed SensorData: Id=1005004 Timestamp=19.04.2018 00:00:04.660 Value=446 ElapsedTime=636
19.04.2018 00:00:06.552 - INFO: Processed SensorData: Id=1005004 Timestamp=19.04.2018 00:00:05.660 Value=32 ElapsedTime=522
19.04.2018 00:00:09.779 - INFO: Processed SensorData: Id=1005004 Timestamp=19.04.2018 00:00:08.682 Value=259.2 ElapsedTime=651
19.04.2018 00:00:10.255 - INFO: Processed SensorData: Id=2301002 Timestamp=19.04.2018 00:00:08.976 Value=0 ElapsedTime=604
19.04.2018 00:00:10.841 - INFO: Processed SensorData: Id=2002100 Timestamp=19.04.2018 00:00:09.383 Value=0 ElapsedTime=445
19.04.2018 00:00:10.773 - INFO: Processed SensorData: Id=2002001 Timestamp=19.04.2018 00:00:09.205 Value=1 ElapsedTime=644
19.04.2018 00:00:11.079 - <<EXCEPTION>>: AggregateException from CloudAppendBlob.AppendTextAsync
19.04.2018 00:00:11.082 - <<EXCEPTION>>: Type =<System.AggregateException> Message =<One or more errors occurred. (One or more errors occurred. (The append position condition specified was not met.))> InnerException.Message=<One or more errors occurred. (The append position condition specified was not met.)>
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.<Dispose>b__8_0()
   at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.RunWithoutSynchronizationContext(Action actionToRun)
   at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at Microsoft.WindowsAzure.Storage.Blob.CloudAppendBlob.<UploadFromStreamAsyncHelper>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Infrastructure.Logging.AzureBlob.Logger.<MessageLogger>d__24.MoveNext() in /opt/vsts/work/1/s/Infrastructure/Logging/Infrastructure.Logging.AzureBlob/Logger.cs:line 183
19.04.2018 00:00:11.479 - INFO: Processed SensorData: Id=2005001 Timestamp=19.04.2018 00:00:09.404 Value=14 ElapsedTime=473
19.04.2018 00:00:11.758 - INFO: Processed SensorData: Id=2006001 Timestamp=19.04.2018 00:00:09.515 Value=15.3 ElapsedTime=677
19.04.2018 00:00:12.059 - INFO: Processed SensorData: Id=1005004 Timestamp=19.04.2018 00:00:09.677 Value=532.3 ElapsedTime=449
19.04.2018 00:00:12.762 - INFO: Processed SensorData: Id=2002102 Timestamp=19.04.2018 00:00:09.558 Value=0 ElapsedTime=561
19.04.2018 00:00:12.714 - INFO: Processed SensorData: Id=2006003 Timestamp=19.04.2018 00:00:09.517 Value=0 ElapsedTime=672
19.04.2018 00:00:13.168 - <<EXCEPTION>>: AggregateException from CloudAppendBlob.AppendTextAsync
19.04.2018 00:00:13.171 - <<EXCEPTION>>: Type =<System.AggregateException> Message =<One or more errors occurred. (One or more errors occurred. (The append position condition specified was not met.))> InnerException.Message=<One or more errors occurred. (The append position condition specified was not met.)>
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.<Dispose>b__8_0()
   at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.RunWithoutSynchronizationContext(Action actionToRun)
   at Microsoft.WindowsAzure.Storage.Blob.BlobWriteStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at Microsoft.WindowsAzure.Storage.Blob.CloudAppendBlob.<UploadFromStreamAsyncHelper>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Infrastructure.Logging.AzureBlob.Logger.<MessageLogger>d__24.MoveNext() in /opt/vsts/work/1/s/Infrastructure/Logging/Infrastructure.Logging.AzureBlob/Logger.cs:line 183
19.04.2018 00:00:13.381 - INFO: Processed SensorData: Id=2003001 Timestamp=19.04.2018 00:00:09.663 Value=1.1 ElapsedTime=483
19.04.2018 00:00:13.749 - INFO: Processed SensorData: Id=2003100 Timestamp=19.04.2018 00:00:09.779 Value=0 ElapsedTime=761

出现此异常的原因可能是什么?

如何进一步解决此问题?

【问题讨论】:

  • OlavT,让我通过我的一些内部联系人来运行它。
  • 您能否通过 AZCommunity[AT]microsoft.com 与我联系,并提供指向此问题的链接以及您的订阅 ID,我们可以帮助您获得针对此问题的支持票证。请在主题字段中提及“ATTN Adam”。

标签: azure-blob-storage


【解决方案1】:

CloudAppendBlob.AppendTextAsync() 的文档标题提到:

此 API 应严格用于单编写器场景,因为该 API 在内部使用附加偏移条件标头来避免重复块,这在多编写器场景中不起作用。

如果您确实需要支持排序不重要的多编写器场景,我建议您使用CloudAppendBlob.AppendBlockAsync()。

【讨论】:

  • 正如我在原始问题中所写,我在严格的单一作者场景中使用它。
猜你喜欢
  • 1970-01-01
  • 2013-07-08
  • 2013-03-27
  • 2012-06-20
  • 1970-01-01
  • 2021-12-13
  • 2020-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多