Azure表存储并发问题

时间:2014-04-02 17:34:27

标签: azure concurrency azure-table-storage optimistic-concurrency

似乎与Azure的并发冲突会在包含错误代码412的消息中抛出异常。除了检查StorageException的错误消息是否包含并发问题之外,还有一种好方法可以告诉由于并发问题而引发异常邮件中有412?这似乎是一种非常串行的方法。

1 个答案:

答案 0 :(得分:2)

使用" RequestInformation.HttpStatusCode似乎对我有用

    try
    {
        TableOperation operation = TableOperation.Merge(ent);
        retval = await table.ExecuteAsync(operation);
    }
    catch (StorageException sex)
    {
        if (sex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve<BotSetting>(ent.PartitionKey, ent.RowKey);
            TableResult retrievedResult = await table.ExecuteAsync(retrieveOperation);
            if (retrievedResult.Result != null)
            {
                BotSetting bs = retrievedResult.Result as BotSetting;
                retval = await TryMerge(table, bs, tries--);
            }
        }
    }