Azure Cosmos DB故障,但确实写入

Azure Cosmos DB故障,但确实写入,azure,azure-cosmosdb,Azure,Azure Cosmosdb,我在给Cosmos DB写信时遇到了一个奇怪的问题。第一次写入似乎失败,出现错误的ResultCode。然而,写操作似乎确实起了作用,当它重试ResultCode时,会出现409冲突 这是一个问题,因为我使用它作为幂等检验,所以我们随后不执行第三方调用 知道我们为什么会有这种行为吗?似乎我们需要关闭一个设置/选项以防止它重试 我们有一个相当简单的文档客户端设置 return new DocumentClient(new Uri(configuration["CosmosDBSett

我在给Cosmos DB写信时遇到了一个奇怪的问题。第一次写入似乎失败,出现
错误的
ResultCode
。然而,写操作似乎确实起了作用,当它重试
ResultCode
时,会出现
409
冲突

这是一个问题,因为我使用它作为幂等检验,所以我们随后不执行第三方调用

知道我们为什么会有这种行为吗?似乎我们需要关闭一个设置/选项以防止它重试

我们有一个相当简单的文档客户端设置

return new DocumentClient(new Uri(configuration["CosmosDBSettings:EndpointUri"]), configuration["CosmosDBSettings:AuthenticationKey"]);
插入文档的代码为:

public async Task<bool> TryInsertReference(Guid paymentReference)
{
    try
    {
        await this.documentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId, VoidCollectionId), new Payment { PaymentReference = paymentReference });
        return true;
    }
    catch (DocumentClientException e) when (e.StatusCode == HttpStatusCode.Conflict)
    {
        return false;
    }
}
    
public async Task Initialise()
{
    await CreateDatabaseIfNotExistsAsync();
    await this.CreateCollectionIfNotExistsAsync(GuaranteeCollectionId);
    await this.CreateCollectionIfNotExistsAsync(VoidCollectionId);
}

private async Task CreateDatabaseIfNotExistsAsync()
{
    try
    {
        await documentClient.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseId));
    }
    catch (DocumentClientException e)
    {
        if (e.StatusCode == HttpStatusCode.NotFound)
        {
            await documentClient.CreateDatabaseAsync(new Database { Id = DatabaseId });
        }
        else
        {
            throw;
        }
    }
}

private async Task CreateCollectionIfNotExistsAsync(string collectionId)
{
    try
    {
        await documentClient.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId, collectionId));
    }
    catch (DocumentClientException e)
    {
        if (e.StatusCode == HttpStatusCode.NotFound)
        {
            await documentClient.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri(DatabaseId), new DocumentCollection { Id = collectionId, DefaultTimeToLive = this.timeToLive });
        }
        else
        {
            throw;
        }
    }
}
公共异步任务tryinserreference(Guid paymentReference)
{
尝试
{
等待这个.documentClient.CreateDocumentSync(UriFactory.CreateDocumentCollectionUri(DatabaseId,VoidCollectionId),新付款{PaymentReference=PaymentReference});
返回true;
}
当(e.StatusCode==HttpStatusCode.Conflict)时捕获(DocumentClientException e)
{
返回false;
}
}
公共异步任务初始化()
{
等待CreateDatabaseIfNoteExistsAsync();
等待此消息。CreateCollectionIfNotExistsAsync(GuaranteCollectionId);
等待此消息。CreateCollectionIfNotExistsAsync(VoidCollectionId);
}
专用异步任务CreateDatabaseIfNoteExistsAsync()
{
尝试
{
等待documentClient.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseId));
}
捕获(DocumentClientException e)
{
if(e.StatusCode==HttpStatusCode.NotFound)
{
等待documentClient.CreateDatabaseAsync(新数据库{Id=DatabaseId});
}
其他的
{
投掷;
}
}
}
专用异步任务CreateCollectionIfNoteExistsAsync(字符串collectionId)
{
尝试
{
等待documentClient.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseId,collectionId));
}
捕获(DocumentClientException e)
{
if(e.StatusCode==HttpStatusCode.NotFound)
{
等待documentClient.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri(DatabaseId),新DocumentCollection{Id=collectionId,DefaultTimeToLive=this.timeToLive});
}
其他的
{
投掷;
}
}
}

请包括实际错误内容和相关代码?发生“故障”事件时会发生什么?你得到了什么错误,或者为什么你认为它是错误的?@ MATASASRANTANA,我在应用程序的洞察力中看到了这是否是宇宙客户端做的,我不是肯定冲突(409),当你为已经存在的“ID”发送一个创建操作,或者你违反了A。如果没有“错误”或错误的详细信息,就不知道如何帮助。当文档不存在时,第一次写入怎么会失败?看看这些日志,第二个结果是409。第一个显然失败了,但确实犯了错误。