Skip to content

Commit dc3d037

Browse files
Subpartitioning: Adds support for Prefix Partition Key searches for sub partitioned containers (#3109)
* 1st round of changes to support subpartitioning for ChangeFeed * name change and moved a method to FeedRangePartitionKey * support for prefix partition change feed and query including unit and emulator tests. need to verify using FeedRange with QueryIterator * splitting out unit tests from emulator tests * 1st round of changes to support subpartitioning for ChangeFeed * name change and moved a method to FeedRangePartitionKey * support for prefix partition change feed and query including unit and emulator tests. need to verify using FeedRange with QueryIterator * splitting out unit tests from emulator tests * moved logic to choose for prefix partition query and change feed * additional conditional to check for MultiHash partitionkeydefinition kind * removed unnecessary using * cleanup * unnecessary using * removed PREVIEW from proj * unit tests for ResolveFeedRangeBasedOnPrefixContainerAsync * change access modifier * since I changed to static, needed to fix tests * dealing with some testing nits * removed Console.Writeline * slight change in test use containerProperties and partitionKeyDefinition * big fix for resolve feedrange, changes to error behavior, added additional test coverage * test changes * ran updateContracts.ps1 * reverting to 3ad5309 * Ran Update Contracts * ran updateContracts.ps1 * UpdateContracts.ps1 * updatecontracts * removed bad check from test, removed changes from updatecontracts.ps1 * revert UpdateContracts changes * Reverting to 756a123 * removed accidental change from changelog * removed unwanted change from Directory.build.props * added test clean up * removed console.writelines * updates to query test * removed preview flag * ran UpdateContrats.ps1 * no longer recread feedRange for queries unless using prefix pk * simplified if statement * fixed bug --------- Co-authored-by: Nalu Tripician <[email protected]>
1 parent f262f89 commit dc3d037

File tree

6 files changed

+809
-186
lines changed

6 files changed

+809
-186
lines changed

Microsoft.Azure.Cosmos/src/Handler/RequestInvokerHandler.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ public virtual async Task<ResponseMessage> SendAsync(
161161

162162
if (feedRange != null)
163163
{
164+
if (!request.OperationType.IsPointOperation())
165+
{
166+
feedRange = await RequestInvokerHandler.ResolveFeedRangeBasedOnPrefixContainerAsync(
167+
feedRange: feedRange,
168+
cosmosContainerCore: cosmosContainerCore,
169+
cancellationToken: cancellationToken);
170+
}
171+
164172
if (feedRange is FeedRangePartitionKey feedRangePartitionKey)
165173
{
166174
if (cosmosContainerCore == null && object.ReferenceEquals(feedRangePartitionKey.PartitionKey, Cosmos.PartitionKey.None))
@@ -480,5 +488,26 @@ private static bool IsClientNoResponseSet(CosmosClientOptions clientOptions, Ope
480488
&& clientOptions.EnableContentResponseOnWrite.HasValue
481489
&& RequestInvokerHandler.IsItemNoRepsonseSet(clientOptions.EnableContentResponseOnWrite.Value, operationType);
482490
}
491+
492+
internal static async Task<FeedRange> ResolveFeedRangeBasedOnPrefixContainerAsync(
493+
FeedRange feedRange,
494+
ContainerInternal cosmosContainerCore,
495+
CancellationToken cancellationToken)
496+
{
497+
if (feedRange is FeedRangePartitionKey feedRangePartitionKey)
498+
{
499+
PartitionKeyDefinition partitionKeyDefinition = await cosmosContainerCore
500+
.GetPartitionKeyDefinitionAsync(cancellationToken)
501+
.ConfigureAwait(false);
502+
503+
if (partitionKeyDefinition != null && partitionKeyDefinition.Kind == PartitionKind.MultiHash
504+
&& feedRangePartitionKey.PartitionKey.InternalKey?.Components?.Count < partitionKeyDefinition.Paths?.Count)
505+
{
506+
feedRange = new FeedRangeEpk(feedRangePartitionKey.PartitionKey.InternalKey.GetEPKRangeForPrefixPartitionKey(partitionKeyDefinition));
507+
}
508+
}
509+
510+
return feedRange;
511+
}
483512
}
484513
}

Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.Items.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -959,12 +959,6 @@ private async Task<ResponseMessage> ExtractPartitionKeyAndProcessItemStreamAsync
959959
// User specified PK value, no need to extract it
960960
if (partitionKey.HasValue)
961961
{
962-
PartitionKeyDefinition pKeyDefinition = await this.GetPartitionKeyDefinitionAsync();
963-
if (partitionKey.HasValue && partitionKey.Value != PartitionKey.None && partitionKey.Value.InternalKey.Components.Count != pKeyDefinition.Paths.Count)
964-
{
965-
throw new ArgumentException(RMResources.MissingPartitionKeyValue);
966-
}
967-
968962
return await this.ProcessItemStreamAsync(
969963
partitionKey,
970964
itemId,

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BulkOperationsAsync.xml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
│ )
3939
├── ItemSerialize(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
4040
├── Get Collection Cache(00000000-0000-0000-0000-000000000000) Routing-Component 00:00:00:000 0.00 milliseconds
41+
│ └── Waiting for Initialization of client to complete(00000000-0000-0000-0000-000000000000) Unknown-Component 00:00:00:000 0.00 milliseconds
42+
├── Read Collection(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
43+
│ (
44+
│ [Client Side Request Stats]
45+
│ Redacted To Not Change The Baselines From Run To Run
46+
│ )
4147
├── Batch Dispatch Async(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
4248
│ ├── Using Wait(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
4349
│ ├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
@@ -72,7 +78,20 @@
7278
},
7379
{
7480
"name": "Get Collection Cache",
75-
"duration in milliseconds": 0
81+
"duration in milliseconds": 0,
82+
"children": [
83+
{
84+
"name": "Waiting for Initialization of client to complete",
85+
"duration in milliseconds": 0
86+
}
87+
]
88+
},
89+
{
90+
"name": "Read Collection",
91+
"duration in milliseconds": 0,
92+
"data": {
93+
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run"
94+
}
7695
},
7796
{
7897
"name": "Batch Dispatch Async",
@@ -1634,6 +1653,12 @@
16341653
│ )
16351654
├── ItemSerialize(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
16361655
├── Get Collection Cache(00000000-0000-0000-0000-000000000000) Routing-Component 00:00:00:000 0.00 milliseconds
1656+
│ └── Waiting for Initialization of client to complete(00000000-0000-0000-0000-000000000000) Unknown-Component 00:00:00:000 0.00 milliseconds
1657+
├── Read Collection(00000000-0000-0000-0000-000000000000) Transport-Component 00:00:00:000 0.00 milliseconds
1658+
│ (
1659+
│ [Client Side Request Stats]
1660+
│ Redacted To Not Change The Baselines From Run To Run
1661+
│ )
16371662
├── Batch Dispatch Async(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
16381663
│ ├── Using Wait(00000000-0000-0000-0000-000000000000) Batch-Component 00:00:00:000 0.00 milliseconds
16391664
│ ├── Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler(00000000-0000-0000-0000-000000000000) RequestHandler-Component 00:00:00:000 0.00 milliseconds
@@ -1808,7 +1833,20 @@
18081833
},
18091834
{
18101835
"name": "Get Collection Cache",
1811-
"duration in milliseconds": 0
1836+
"duration in milliseconds": 0,
1837+
"children": [
1838+
{
1839+
"name": "Waiting for Initialization of client to complete",
1840+
"duration in milliseconds": 0
1841+
}
1842+
]
1843+
},
1844+
{
1845+
"name": "Read Collection",
1846+
"duration in milliseconds": 0,
1847+
"data": {
1848+
"Client Side Request Stats": "Redacted To Not Change The Baselines From Run To Run"
1849+
}
18121850
},
18131851
{
18141852
"name": "Batch Dispatch Async",

0 commit comments

Comments
 (0)