【发布时间】:2020-02-13 17:17:43
【问题描述】:
我已使用URLshortener 的 GitHub 解决方案并将其部署在我的 Azure 租户上。现在突然我收到一个错误:
"Exception while executing function: Functions.UrlIngest.
Microsoft.Azure.WebJobs.Host: Error while handling parameter keyTable after
function returned:. Microsoft.WindowsAzure.Storage: The remote server
returned an error: (412) Precondition Failed."
在研究这个问题的时候,我发现了一个link,上面写着:
"If the entity's ETag differs from that specified with the update request,
the update operation fails with status code 412 (Precondition Failed). This
error indicates that the entity has been changed on the server since it was
retrieved. To resolve this error, retrieve the entity again and reissue the request."
因此,为了解决这个问题,我对 Azure 函数代码进行了以下更改:
try
{
await tableOut.ExecuteAsync(operation);
}
catch (StorageException ex)
{
if (ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed)
{
log.Info("Precondition failure as expected.");
TableOperation retrieveOperation = TableOperation.Retrieve<NextId>(keyTable.PartitionKey, keyTable.RowKey);
// Execute the operation.
TableResult retrievedResult = tableOut.Execute(retrieveOperation);
int idCount = keyTable.Id;
// Assign the result to a CustomerEntity object.
keyTable = (NextId)retrievedResult.Result;
if (keyTable != null)
{
// Change the phone number.
keyTable.Id = idCount;
// Create the Replace TableOperation.
TableOperation updateOperation = TableOperation.Replace(keyTable);
// Execute the operation.
tableOut.Execute(updateOperation);
log.Info("Entity updated.");
}
else
{
log.Info("Entity could not be retrieved.");
}
}
}
它仍然会抛出相同的错误,但是当我检查 Azure 表存储时,它具有正确的值。
谁能帮我解决这个问题?
【问题讨论】:
标签: azure azure-functions azure-table-storage optimistic-concurrency