跨分区使用相同ID创建文档失败

时间:2019-12-19 08:46:18

标签: azure-cosmosdb

我们正在尝试在不同分区之间创建具有相同ID的文档

更新失败,并显示错误

在Azure Cosmos中

{
    "code": 409,
    "body": {
        "code": "Conflict",
        "message": "Entity with the specified id already exists in the system., \r\nRequestStartTime: 2019-12-19T08:34:37.5860449Z, RequestEndTime: 2019-12-19T08:34:37.5961787Z, Number of regions attempted:1\r\nResponseTime: 2019-12-19T08:34:37.5961787Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westus1-fd41.documents.azure.com:14086/apps/06af805e-8590-4705-9817-859c9fa7bdc4/services/fb1ffb13-843f-4459-b668-80186964b5fc/partitions/ca683c98-0daf-42f9-8408-cecff98b3d7f/replicas/132212042754425215p/, LSN: 3, GlobalCommittedLsn: 3, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 409, SubStatusCode: 3302, RequestCharge: 1.57, ItemLSN: -1, SessionToken: -1#3, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Create\r\n, Microsoft.Azure.Documents.Common/2.7.0"
    },
    "headers": {
        <snipped>
    },
    "activityId": "3182f9a5-6c44-48e9-85af-642fcc1b0b86",
    "substatus": 3302
}

在模拟器中 容器Collection_L1_Test的文档创建错误-文件docDbBug.txt:

{
    "code": 409,
    "body": "{\"code\":\"Conflict\",\"message\":\"Message: {\\\"Errors\\\":[\\\"Resource with specified id or name already exists.\\\",\\\"Resource with id already exists with a conflicting hashed partition key, Please retry with a different partition key.\\\"]}\\r\\nActivityId: f8e002d8-04e9-4a69-821b-01ca483f8789, Request URI: /apps/DocDbApp/services/DocDbServer12/partitions/a4cb4958-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: \\r\\nRequestStartTime: 2019-12-19T08:13:52.5769961Z, RequestEndTime: 2019-12-19T08:13:52.5779926Z, Number of regions attempted:1\\r\\nResponseTime: 2019-12-19T08:13:52.5779926Z, StoreResult: StorePhysicalAddress: rntbd://127.0.0.1:10253/apps/DocDbApp/services/DocDbServer12/partitions/a4cb4958-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 203, GlobalCommittedLsn: -1, PartitionKeyRangeId: 1, IsValid: True, StatusCode: 409, SubStatusCode: 3302, RequestCharge: 1.57, ItemLSN: -1, SessionToken: 203, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Create\\r\\n, SDK: Microsoft.Azure.Documents.Common/2.7.0\"}",
    "activityId": "f8e002d8-04e9-4a69-821b-01ca483f8789",
    "substatus": 3302
}

https://docs.microsoft.com/en-us/azure/cosmos-db/unique-keys看来,Id的唯一性在上述实验的分区级别上 ID必须在集合级别唯一

假设分区键+ id是集合内的唯一组合是不安全的吗?

P.S。可以通过先将docDbBug.txt添加到一个cosmos DB(SQL类型)中,然后尝试在同一集合中添加docDbBugUpdate.txt来实现repro。 (两个文件都已附加)

1 个答案:

答案 0 :(得分:0)

可以使用Cosmos DB集合中id和partitionkey的组合来唯一地标识文档。

这里的问题可能是由于分区键值很大。

“如果有多个具有相同的前100个字节的分区键,则这些逻辑分区将被服务视为相同的逻辑分区。” 请参阅https://docs.microsoft.com/en-us/azure/cosmos-db/large-partition-keys