Skip to content

BulkMode: Adds PartitionKeyRangeId in Bulk Mode and TransactionalBatch Response Headers #4240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public virtual bool IsSuccessStatusCode
/// </summary>
internal virtual string SessionToken { get; set; }

/// <summary>
/// A string containing the partition key range id assigned to this result.
/// </summary>
internal virtual string PartitionKeyRangeId { get; set; }

/// <summary>
/// ActivityId related to the operation
/// </summary>
Expand Down Expand Up @@ -218,6 +223,7 @@ internal ResponseMessage ToResponseMessage(ContainerInternal cosmosContainerCore
RetryAfter = this.RetryAfter,
RequestCharge = this.RequestCharge,
Session = this.SessionToken,
PartitionKeyRangeId = this.PartitionKeyRangeId,
ActivityId = this.ActivityId,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private void CreateAndPopulateResults(IReadOnlyList<ItemBatchOperation> operatio
SubStatusCode = this.SubStatusCode,
RetryAfter = TimeSpan.FromMilliseconds(retryAfterMilliseconds),
SessionToken = this.Headers.Session,
PartitionKeyRangeId = this.Headers.PartitionKeyRangeId,
ActivityId = this.ActivityId,
};

Expand Down Expand Up @@ -345,6 +346,7 @@ private static async Task<TransactionalBatchResponse> PopulateFromContentAsync(

operationResult.Trace = trace;
operationResult.SessionToken = responseMessage.Headers.Session;
operationResult.PartitionKeyRangeId = responseMessage.Headers.PartitionKeyRangeId;
operationResult.ActivityId = responseMessage.Headers.ActivityId;

results.Add(operationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public async Task DoOperationsAsync()

MyDocument document = cosmosDefaultJsonSerializer.FromStream<MyDocument>(result.ResourceStream);
Assert.AreEqual(i.ToString(), document.id);
Assert.IsNotNull(result.PartitionKeyRangeId);

ItemResponse<MyDocument> storedDoc = await this.cosmosContainer.ReadItemAsync<MyDocument>(i.ToString(), new Cosmos.PartitionKey(i.ToString()));
Assert.IsNotNull(storedDoc.Resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public async Task CreateItemStream_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
ToDoActivity document = TestCommon.SerializerCore.FromStream<ToDoActivity>(result.Content);
Assert.AreEqual(i.ToString(), document.id);
Expand All @@ -120,6 +121,7 @@ public async Task CreateItemAsync_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
}
Expand Down Expand Up @@ -197,6 +199,7 @@ public async Task CreateItemAsyncValidateIntendedCollRid_WithBulk()
Task<ItemResponse<ToDoActivity>> task = tasks[i];
ItemResponse<ToDoActivity> result = await task;
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
}
Expand Down Expand Up @@ -228,6 +231,7 @@ public async Task CreateItemAsyncValidateIntendedCollRid_WithBulk()
Task<ItemResponse<ToDoActivity>> task = tasks[i];
ItemResponse<ToDoActivity> result = await task;
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
}
Expand All @@ -251,6 +255,7 @@ public async Task CreateItemJObjectWithoutPK_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
}
Expand All @@ -275,6 +280,7 @@ public async Task UpsertItemStream_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
ToDoActivity document = TestCommon.SerializerCore.FromStream<ToDoActivity>(result.Content);
Assert.AreEqual(i.ToString(), document.id);
Expand All @@ -299,6 +305,7 @@ public async Task UpsertItem_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
}
Expand Down Expand Up @@ -334,6 +341,7 @@ public async Task DeleteItemStream_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
}
Expand Down Expand Up @@ -369,6 +377,7 @@ public async Task DeleteItem_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
}
Expand Down Expand Up @@ -404,6 +413,7 @@ public async Task ReadItemStream_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
Expand Down Expand Up @@ -439,6 +449,7 @@ public async Task ReadItem_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
Expand Down Expand Up @@ -474,6 +485,7 @@ public async Task ReplaceItemStream_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
Expand Down Expand Up @@ -509,6 +521,7 @@ public async Task ReplaceItem_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
Expand Down Expand Up @@ -548,6 +561,7 @@ public async Task PatchItemStream_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
Expand Down Expand Up @@ -587,6 +601,7 @@ public async Task PatchItem_WithBulk()
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
Assert.AreEqual("patched", result.Resource.description);
Expand Down Expand Up @@ -630,6 +645,7 @@ private async Task CreateLargeItemStreamWithBulk(int appxItemSize)
Assert.IsTrue(result.Headers.RequestCharge > 0);
Assert.IsNotNull(result.Headers.Session);
Assert.IsNotNull(result.Headers.ActivityId);
Assert.IsNotNull(result.Headers.PartitionKeyRangeId);
Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
}
Expand Down