【问题标题】:Azure StorageException when using emulated storage (within documented constraints)使用模拟存储时出现 Azure StorageException(在记录的约束范围内)
【发布时间】:2017-06-26 06:56:38
【问题描述】:

我们的应用程序执行了几批TableBatchOperation。我们确保这些表批处理操作中的每一个都有

  • 100 个或更少的表操作
  • 仅针对一个实体分区键的表操作

大致如下:

        foreach (var batch in batches)
        {
            var operation = new TableBatchOperation();
            operation.AddRange(batch.Select(x => TableOperation.InsertOrReplace(x)));
            await table.ExecuteBatchAsync(operation);
        }
  • 当我们使用 emulated 存储时,我们遇到了 Microsoft.WindowsAzure.Storage.StorageException - “批处理中的元素 99 返回了意外的响应代码。”
  • 当我们使用生产 Azure 时,一切正常。

模拟存储配置如下:

<add key="StorageConnectionString" value="UseDevelopmentStorage=true;" />

我担心,尽管在生产环境(我们使用真正的 Azure)中一切正常,但它被模拟存储所破坏的事实可能表明我们做了一些我们不应该做的事情。

我已经用调试器运行了它(在它崩溃之前)并验证了它(根据 API):

  • 整个操作序列化为 JSON 时只有 492093 个字符(UTF-16 为 984186 个字节)
  • 正好有 100 个操作
  • 所有实体都具有相同的分区键

https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.table.tablebatchoperation?view=azurestorage-8.1.3

编辑: 看起来其中一项 (#71/100) 导致此失败。从结构上讲,它与其他项目没有什么不同,但它确实有一些相当长的字符串属性 - 所以可能存在未记录的限制/错误?

编辑: 以下 Unicode UTF-16 字节序列(在字符串属性上)足以导致异常:

r     e     n     U+0019         space
114 0 101 0 110 0 25 0 115 0 32 0

(是字节 25 0 115 0 即导致异常的 unicode end-of-medium U+0019)。

编辑: 失败实体的完整示例:

JSON:

{"SomeProperty":"ren\u0019s ","PartitionKey":"SomePartitionKey","RowKey":"SomeRowKey","Timestamp":"0001-01-01T00:00:00+00:00","ETag":null}

实体类:

public class TestEntity : TableEntity
{
    public string SomeProperty { get; set; }
}

实体对象构造:

var entity = new TestEntity
{
    SomeProperty = Encoding.Unicode.GetString(new byte[]
        {114, 0, 101, 0, 110, 0, 25, 0, 115, 0, 32, 0}),
    PartitionKey = "SomePartitionKey",
    RowKey = "SomeRowKey"
};

【问题讨论】:

  • 你能分享一下最后一个实体的数据是什么样的吗?当您从批处理操作中删除最后一个实体时会发生什么?批处理是否成功?
  • 最后一个实体看起来一点也不特别。只是一个 POCO(源自 Microsoft.WindowsAzure.Storage.Table.TableEntity)。删除最后一个实体并没有成功(我们看到“批次中的元素 98...”)。我的测试表明,对于这个特定的数据,它成功了 70 个项目,但失败了 71 个。从那以后,我只用第 71 个项目单独尝试过它,但它失败了 - 所以问题一定出在那个项目上。
  • 我很想看看失败实体的数据。
  • 使用 Windows Azure 存储模拟器 5.1.0.0
  • 我在 MSDN 论坛上发帖:social.msdn.microsoft.com/Forums/azure/en-US/…

标签: azure azure-table-storage azure-emulator


【解决方案1】:

根据您的描述,我也可以重现您提到的问题。经过我的测试,我发现特别 Azure 存储模拟器 似乎不支持 Unicode 字符“END OF MEDIUM”(U+0019)。如果可以替换为其他 unicode,请尝试使用其他 unicode 来代替。

我们也可以将 feedback 提供给 Azure 存储团队。

【讨论】:

  • 这是为什么呢?当然,模拟器应该支持有效的 C# 字符串,就像真正的 Azure 一样。似乎我们应该提出错误报告 - 不过我找不到这样做的地方。
  • 1. Why is that? 仅基于我的测试。我还从document 中找到了一些相关信息。 If you use a version of the storage services that is not yet supported by the emulator, the storage emulator returns a VersionNotSupportedByEmulator error (HTTP status code 400 - Bad Request) 2. I couldn't find the place to raise a bug.正如我上面提到的,我们可以将我们的 feedback 交给 azure 团队。
  • 我使用该反馈链接发布了一个“想法”。真的,我想要一种报告错误的机制。不过还是谢谢:)
猜你喜欢
  • 2017-01-28
  • 1970-01-01
  • 2021-03-22
  • 2018-05-30
  • 2011-05-23
  • 2016-09-29
  • 2015-06-21
  • 2018-12-03
  • 2020-08-09
相关资源
最近更新 更多