Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
579 stars 840 forks source link

CreateAttachmentAsync failed on collection with partitionKey on #776

Open joviledog opened 4 years ago

joviledog commented 4 years ago

Hi, I created a document in a cosmosdb using Microsoft.Azure.DocumentDB 2.10.1.

The next step is I used the CreateAttachmentAsync API and passed in the document link, with an attachment, the requestOptions has one explicit override where the PartitionKey is set to the collection predefined partition key of /taskType.

The input are: documentLink: "dbs/moneypenny-scratch-docdb/colls/ExternalTasksBackup/docs/eb72f518-d1c7-4dfa-9c23-252e010f2083" Attachment: attachment {{ "id": "blob", "media": "http://127.0.0.1:10000/devstoreaccount1/moneypennyscratchstorage/ExternalTaskRecord/eb72f518-d1c7-4dfa-9c23-252e010f2083", "contentType": "application/json" }} Microsoft.Azure.Documents.Attachment

requestOptions:

The error that I got is: {{ "code": "NotFound", "message": "Message: {\"Errors\":[\"Owner resource does not exist\"]}\r\n ActivityId: 6e58c2ef-91f9-4220-8c86-98f77d243711, Request URI: /apps/DocDbApp/services/DocDbServer12/partitions/a4cb4958-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: \r\nRequestStartTime: 2020-03-11T19:53:45.9004666Z, RequestEndTime: 2020-03-11T19:53:45.9104389Z,
Number of regions attempted:1\r\nResponseTime: 2020-03-11T19:53:45.9104389Z, StoreResult: StorePhysicalAddress: rntbd://127.0.0.1:10253/apps/DocDbApp/services/DocDbServer12/partitions/a4cb4958-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 15, GlobalCommittedLsn: -1, PartitionKeyRangeId: 1, IsValid: True, StatusCode: 404, SubStatusCode: 1003, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#15, UsingLocalLSN: False, TransportException: null, ResourceType: Attachment, OperationType: Create\r\n, SDK: documentdb-dotnet-sdk/2.10.1 Host/32-bit MicrosoftWindowsNT/6.2.9200.0" CallStack: at Microsoft.Azure.Documents.StoreResult.ToResponse(RequestChargeTracker requestChargeTracker) at Microsoft.Azure.Documents.ConsistencyWriter.d18.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.BackoffRetryUtility`1.d5.MoveNext() at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException) at Microsoft.Azure.Documents.BackoffRetryUtility1.<ExecuteRetryAsync>d__5.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.ConsistencyWriter.<WriteAsync>d__17.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.ReplicatedResourceClient.<>c__DisplayClass27_0.<<InvokeAsync>b__0>d.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Azure.Documents.RequestRetryUtility.<ProcessRequestAsync>d__22.MoveNext() at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException) at Microsoft.Azure.Documents.RequestRetryUtility.d2`2.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.StoreClient.d19.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.ServerStoreModel.d15.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.Client.DocumentClient.d159.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.Client.DocumentClient.d158.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.Client.DocumentClient.d330.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Documents.BackoffRetryUtility1.<ExecuteRetryAsync>d__5.MoveNext() at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException) at Microsoft.Azure.Documents.BackoffRetryUtility1.d5.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.Azure.DocumentDBStudio.ResourceNode.d29.MoveNext() in C:\source\documentdbStudio\DocumentDBStudio\Nodes\ResourceNode.cs:line 661

When I created a parallel collection without partitionKey enabled and I added a document, I could use the same CreateAttachmentAsync call to create the attachment. I am not sure why this API failed on collection that the partitionKey enabled. The above log is capturing from using my local copy against CosmosDb emulator 2.9.2.0 but the problem initially happened in a real-world Azure environment so I am wondering if we have done something wrong with the way we use CreateAttachmentAsync on a document persisted in a partitioned collection.

joviledog commented 4 years ago

The first attempt was using the uri style document link. I tried the 2nd round using the legacy selflink of the document: "dbs/5wdgAA==/colls/5wdgAM7fQCI=/docs/5wdgAM7fQCINAAAAAAAACA==/"

The error is slightly different and reported Resource Not Found Message: {"Errors":["Resource Not Found"]} ActivityId: e0556d83-56ca-4a14-bf07-2685001eaf2f, Request URI: /apps/DocDbApp/services/DocDbServer12/partitions/a4cb4958-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: RequestStartTime: 2020-03-11T21:08:52.6227389Z, RequestEndTime: 2020-03-11T21:08:52.6416887Z, Number of regions attempted:1 ResponseTime: 2020-03-11T21:08:52.6416887Z, StoreResult: StorePhysicalAddress: rntbd://127.0.0.1:10253/apps/DocDbApp/services/DocDbServer12/partitions/a4cb4958-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 28, GlobalCommittedLsn: -1, PartitionKeyRangeId: 1, IsValid: True, StatusCode: 404, SubStatusCode: 1003, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#28, UsingLocalLSN: False, TransportException: null, ResourceType: Attachment, OperationType: Create , SDK: documentdb-dotnet-sdk/2.10.1 Host/32-bit MicrosoftWindowsNT/6.2.9200.0