Skip to content
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

CFP AVAD: Adds Container IsFeedRangePartOfAsync support for FeedRange #4566

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
a71d474
initial checkin
philipthomas-MSFT May 16, 2024
749c7ff
feedRangeFetails added to headers as a tuple. may created a public ty…
philipthomas-MSFT May 30, 2024
158b26d
FeedRangeDetail type in place of tuple
philipthomas-MSFT May 30, 2024
5472e18
some tests but impl is incomplete
philipthomas-MSFT Jun 3, 2024
1889f0f
merge
philipthomas-MSFT Jul 2, 2024
5e3f277
merge
philipthomas-MSFT Jul 2, 2024
02b220e
revert after bad merge
philipthomas-MSFT Jul 2, 2024
ae7ea26
revert after a bad merge
philipthomas-MSFT Jul 2, 2024
003da7e
revert after a bad merge
philipthomas-MSFT Jul 2, 2024
4af2d91
changes
philipthomas-MSFT Jul 8, 2024
96262c0
more test to come
philipthomas-MSFT Jul 15, 2024
00e32d3
add a test for FeedRange on Header, Find overlapping ranges using Par…
philipthomas-MSFT Jul 16, 2024
8fc8608
removing the type FeedRangeDetails, collectionRId was not needed.
philipthomas-MSFT Jul 16, 2024
d62f05f
mark as Preview
philipthomas-MSFT Jul 16, 2024
76ee8f0
FindOverlappingRanges test. Just FeedRange.
philipthomas-MSFT Jul 17, 2024
5b2cd52
The start, not finished, test for container.FindOverlappingRangesAsync
philipthomas-MSFT Jul 17, 2024
18ce956
partition key tests
philipthomas-MSFT Jul 18, 2024
b1ed9a1
more testing. still not satisfied. will do more until the end of week.
philipthomas-MSFT Jul 18, 2024
df0eb32
more test changes.
philipthomas-MSFT Jul 22, 2024
77be0f9
add partitionkey to test
philipthomas-MSFT Jul 22, 2024
570d5ea
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Jul 22, 2024
e3e3f23
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Jul 23, 2024
5976251
merge master
philipthomas-MSFT Jul 23, 2024
a026438
merge master
philipthomas-MSFT Jul 23, 2024
843be8f
re-run UpdateContracts.ps1
philipthomas-MSFT Jul 23, 2024
5cbb0d6
more tests alterations.
philipthomas-MSFT Jul 23, 2024
caff01e
add cancellation token to test.
philipthomas-MSFT Jul 23, 2024
4cf2fea
just some test changes
philipthomas-MSFT Jul 23, 2024
0c56179
fix issue with FeedRangeEpk
philipthomas-MSFT Jul 23, 2024
563ddb9
some test changes from meeting.
philipthomas-MSFT Jul 23, 2024
73b912a
re-run update contracts.
philipthomas-MSFT Jul 23, 2024
771c487
making it work.
philipthomas-MSFT Jul 23, 2024
6559eb0
sdd to EncryptionContainer.cs
philipthomas-MSFT Jul 23, 2024
5e2a0b6
some formatting and change to Debug for logging before Logger.LogLine…
philipthomas-MSFT Jul 23, 2024
bda2f44
test update
philipthomas-MSFT Jul 29, 2024
f5016d8
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Jul 29, 2024
b02f35a
fix EncryptionContainer
philipthomas-MSFT Jul 29, 2024
b5a65c8
remove a test helper method that is no longer needed. and updated tes…
philipthomas-MSFT Jul 29, 2024
9cee550
trying to fix EncryptionContainer
philipthomas-MSFT Jul 29, 2024
1efe714
try, try again
philipthomas-MSFT Jul 29, 2024
0b0001b
hmm
philipthomas-MSFT Jul 29, 2024
8fc3537
fixing a test.
philipthomas-MSFT Jul 29, 2024
f4745af
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Jul 31, 2024
9d3fb3e
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Aug 1, 2024
c848800
removing other features and boiling it down to just FindOverlappingRa…
philipthomas-MSFT Aug 1, 2024
ce57c96
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Aug 5, 2024
490fe03
move rangeFromPartitionKey out of loop.
philipthomas-MSFT Aug 5, 2024
90a6232
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Aug 6, 2024
6556dc6
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Aug 14, 2024
e57ce18
IsSubset
philipthomas-MSFT Aug 14, 2024
cc4c4f3
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Aug 14, 2024
64ba764
removed from Encryption
philipthomas-MSFT Aug 14, 2024
f5fc5bb
add back GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes<T>
philipthomas-MSFT Aug 14, 2024
5fe347f
reverting back to origin
philipthomas-MSFT Aug 14, 2024
df9fecd
NotImplementedException>() fix on container
philipthomas-MSFT Aug 14, 2024
78618cd
reverting sln
philipthomas-MSFT Aug 14, 2024
1378a55
hmm. these baseline files.
philipthomas-MSFT Aug 14, 2024
a9d59a2
revwer to origin
philipthomas-MSFT Aug 15, 2024
b45f34b
removed api for PartitionKey since user can call FeedRange.FromPartit…
philipthomas-MSFT Aug 15, 2024
fb05663
reworked IsSubsetAsync based on suggestions to use FeedRangeInteranl …
philipthomas-MSFT Aug 15, 2024
50185b6
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Aug 16, 2024
77a1897
some subset changes. and tests.
philipthomas-MSFT Aug 16, 2024
8f07db8
missing using directive
philipthomas-MSFT Aug 16, 2024
6aa9487
type Overlaps instead of dynamic type. Fix IsSubset to include equal to.
philipthomas-MSFT Aug 19, 2024
8e96a69
Overlaps list
philipthomas-MSFT Aug 19, 2024
72770f2
update logic for IsSubset
philipthomas-MSFT Aug 20, 2024
83992d8
removed Overlap type. No longer needed.
philipthomas-MSFT Aug 20, 2024
a7119a2
ArgumentException to include expect and actual type.
philipthomas-MSFT Aug 21, 2024
354dbbe
include basic code sample references in code-doc.
philipthomas-MSFT Aug 21, 2024
7026c3b
default argument for CancellationToken parameter
philipthomas-MSFT Aug 21, 2024
68e15c5
removed NoOpTrace
philipthomas-MSFT Aug 21, 2024
efc7c8c
another default argument for CancellationToken parameter
philipthomas-MSFT Aug 21, 2024
bd8f56a
discovering the smallest Min and the largest Max from an array of Doc…
philipthomas-MSFT Aug 21, 2024
36c3e5f
some refactoring. also dealing with ranges that are FeedRangePartitio…
philipthomas-MSFT Aug 22, 2024
74f7fab
removed an unnecessary getEffectoveRamgesAsync call.
philipthomas-MSFT Aug 22, 2024
8cfd9f3
Merge remote-tracking branch 'origin/master' into users/philipthomas-…
philipthomas-MSFT Aug 22, 2024
a381687
not sure why this changed.
philipthomas-MSFT Aug 22, 2024
edf36d4
hmm. add try catch back.
philipthomas-MSFT Aug 22, 2024
c3e8d64
Merge branch 'master' of https://github.com/Azure/azure-cosmos-dotnet…
philipthomas-MSFT Sep 6, 2024
bbed6d4
name refactoring. TryParse on parent and child json. DocumentClientEx…
philipthomas-MSFT Sep 6, 2024
53848de
validation and error checks with tests.
philipthomas-MSFT Sep 10, 2024
683bebb
rename refactoring
philipthomas-MSFT Sep 10, 2024
0eef412
unused using directives.
philipthomas-MSFT Sep 10, 2024
3606d62
Normalized Ranges impl
philipthomas-MSFT Sep 10, 2024
4f59d6a
more tests
philipthomas-MSFT Sep 10, 2024
976e21f
remove comment and alias. not necessary. using Last.Max to avoid reso…
philipthomas-MSFT Sep 10, 2024
0d70411
IsMinInclusive check on FeedRangeEpk. remove normalization of FeedRange
philipthomas-MSFT Sep 12, 2024
8a8f229
removed usings
philipthomas-MSFT Sep 12, 2024
5e33500
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 12, 2024
d5a999b
ok. should add these usings back.
philipthomas-MSFT Sep 12, 2024
c2e6d52
test updates. documentation for clarity. some refactoring.
philipthomas-MSFT Sep 12, 2024
5b60151
IsSubset tests
philipthomas-MSFT Sep 12, 2024
46db601
Add Display. a nit.
philipthomas-MSFT Sep 12, 2024
4d84158
no idea why I changed this.
philipthomas-MSFT Sep 13, 2024
fff0458
EnsureConsistentInclusivity
philipthomas-MSFT Sep 15, 2024
3463fab
various changes. PREVIEW. FeedRangeInternal check before TryParse on …
philipthomas-MSFT Sep 16, 2024
58d1122
moving test to create a single instance of Containers
philipthomas-MSFT Sep 16, 2024
c43d063
removed duplicated test data row.
philipthomas-MSFT Sep 16, 2024
b6e5e29
removal of unnecessary comments since I am describing the scenarios.
philipthomas-MSFT Sep 16, 2024
f860d12
missed a container instance
philipthomas-MSFT Sep 16, 2024
801c1a8
missed another container reference
philipthomas-MSFT Sep 16, 2024
4c84f8e
revert since new tests have new tests file
philipthomas-MSFT Sep 16, 2024
c6bff5b
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 16, 2024
846dfb4
add another test scenario
philipthomas-MSFT Sep 16, 2024
91708f9
fix displayname
philipthomas-MSFT Sep 16, 2024
769c8e4
more scenarios
philipthomas-MSFT Sep 16, 2024
e0319dd
move ensureConsistentInclusivity to check on effectiveRanges outside …
philipthomas-MSFT Sep 16, 2024
e7bde88
adding comments, but thinking of a better way to deal and manage this…
philipthomas-MSFT Sep 17, 2024
4b3b079
introducing Gherkin interpreter to have a discussion with Team to see…
philipthomas-MSFT Sep 17, 2024
bfa9740
remove gherkin. will follow up on dynamic building of scenarios.
philipthomas-MSFT Sep 17, 2024
003a17d
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 18, 2024
b82a731
reverting to master
philipthomas-MSFT Sep 18, 2024
a45b646
new tests for IsSubset with strategy for creating inclusive or exclus…
philipthomas-MSFT Sep 18, 2024
4f50db2
removed from EncryptionContainer
philipthomas-MSFT Sep 18, 2024
5e68c03
need to fix a test.
philipthomas-MSFT Sep 18, 2024
0735b65
revert test.
philipthomas-MSFT Sep 18, 2024
3783530
adding this back
philipthomas-MSFT Sep 18, 2024
3a2608c
encryption container fix
philipthomas-MSFT Sep 18, 2024
b553c72
add more comments
philipthomas-MSFT Sep 18, 2024
f2ea6c4
fix broken test
philipthomas-MSFT Sep 18, 2024
43ffba1
add impl
philipthomas-MSFT Sep 18, 2024
2a3a197
reverting
philipthomas-MSFT Sep 18, 2024
feaeb8f
virutal on Container. some things may fail.
philipthomas-MSFT Sep 18, 2024
dfe5feb
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
kirankumarkolli Sep 18, 2024
6d77041
change test for IsSubset again. Not dynamic anymore.
philipthomas-MSFT Sep 18, 2024
2cd8d75
Merge branch 'users/philipthomas-MSFT/add_feedranges_to_avad_contract…
philipthomas-MSFT Sep 18, 2024
05e87a0
update summary
philipthomas-MSFT Sep 18, 2024
0876202
removed unnecessary comment
philipthomas-MSFT Sep 18, 2024
4ffe30c
removed some scenarios
philipthomas-MSFT Sep 18, 2024
fb7b942
add PREVIEW flag
philipthomas-MSFT Sep 18, 2024
0a8e36d
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 18, 2024
7868ef6
updatecontracts
philipthomas-MSFT Sep 18, 2024
acbad19
include more scenarios
philipthomas-MSFT Sep 18, 2024
6140a90
add verbage
philipthomas-MSFT Sep 18, 2024
f235378
add IsFeedRangePartofAsync in ContainerCore.
philipthomas-MSFT Sep 19, 2024
a7f048a
new scenarios to illustrate my point in conversation
philipthomas-MSFT Sep 19, 2024
8497db9
add DisplayName for 2 DataRows
philipthomas-MSFT Sep 19, 2024
35acb5f
since name changed from IsSubset to IsFeedRangePartOfAsync, fixing tr…
philipthomas-MSFT Sep 19, 2024
1b17ab7
trying Diagram 2 with ContainerInternal instead of ContainerInlineCore
philipthomas-MSFT Sep 19, 2024
76940cc
fix to IsSub and test that are affected.
philipthomas-MSFT Sep 19, 2024
10898e0
overriding in ContainerInlineCore, but not using operations helper, etc.
philipthomas-MSFT Sep 20, 2024
8790e7b
fix test implementation for IsSubset. add more DataRows
philipthomas-MSFT Sep 21, 2024
3d8d306
issue with summary
philipthomas-MSFT Sep 21, 2024
b6ab81e
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 21, 2024
5bbad51
removed Range<string> from summary
philipthomas-MSFT Sep 21, 2024
07a294b
add more scenarios and reorganized the DataRows
philipthomas-MSFT Sep 23, 2024
5bb871b
move some documentation around
philipthomas-MSFT Sep 23, 2024
a6d4eda
wrap async method in OperationHelperAsync for consistency
philipthomas-MSFT Sep 23, 2024
de79711
add TODO about Documents.OperationType.ReadFeed on operations not rel…
philipthomas-MSFT Sep 23, 2024
e5846c9
ranges is null empty so just pull the first one. also update summary.
philipthomas-MSFT Sep 24, 2024
e4790d4
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 25, 2024
0169f4c
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 26, 2024
4e2a95b
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 30, 2024
6a5d8e7
add this scenario "AA", "AA", true, "", "AA", false, false
philipthomas-MSFT Sep 30, 2024
56775bb
adding scenario "AA", "AA", true, "AA", "AZ", false, true
philipthomas-MSFT Sep 30, 2024
bed52de
all recent new scenarios
philipthomas-MSFT Sep 30, 2024
c9f2763
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
kirankumarkolli Sep 30, 2024
8e008fb
made a change for isSubset to substract the max if MaxExclusive. spec…
philipthomas-MSFT Sep 30, 2024
bde2252
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Sep 30, 2024
8989c7b
Merge branch 'users/philipthomas-MSFT/add_feedranges_to_avad_contract…
philipthomas-MSFT Sep 30, 2024
81e1499
renaiming parent and child to x and y, respectively, for Container.cs
philipthomas-MSFT Sep 30, 2024
9dff5c5
test to include all types of containers.
philipthomas-MSFT Oct 1, 2024
8aec5b9
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
kirankumarkolli Oct 1, 2024
fe03634
remove dead code.
philipthomas-MSFT Oct 2, 2024
09fa5d0
fix params
philipthomas-MSFT Oct 2, 2024
248b929
reverted these
philipthomas-MSFT Oct 2, 2024
ccc3009
remove named parameters because local test use parent/child parameter…
philipthomas-MSFT Oct 2, 2024
48213d0
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Oct 2, 2024
77dab06
Update Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs
philipthomas-MSFT Oct 2, 2024
23bdc17
Update Microsoft.Azure.Cosmos/src/Resource/Container/ContainerCore.It…
philipthomas-MSFT Oct 2, 2024
860dbc7
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Oct 2, 2024
10d6c9a
update docs
philipthomas-MSFT Oct 2, 2024
ba71dd0
Merge branch 'users/philipthomas-MSFT/add_feedranges_to_avad_contract…
philipthomas-MSFT Oct 2, 2024
4ebbad9
change parent to x, and child to y, everywhere.
philipthomas-MSFT Oct 3, 2024
2a63b12
Merge branch 'master' into users/philipthomas-MSFT/add_feedranges_to_…
philipthomas-MSFT Oct 3, 2024
0c4df8e
removed extra params
philipthomas-MSFT Oct 3, 2024
8441b34
extraa return removed
philipthomas-MSFT Oct 3, 2024
855810b
done.
philipthomas-MSFT Oct 3, 2024
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 @@ -59,13 +59,15 @@ public static ChangeFeedPartitionKeyResultSetIteratorCore Create(
container: container,
mode: mode,
changeFeedStartFrom: startFrom,
options: requestOptions);
options: requestOptions,
feedRangeEpk: lease?.FeedRange is FeedRangeEpk epk ? epk : default);
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
}

private readonly CosmosClientContext clientContext;

private readonly ChangeFeedRequestOptions changeFeedOptions;
private readonly ChangeFeedMode mode;
private readonly FeedRangeEpk feedRangeEpk;

private ChangeFeedStartFrom changeFeedStartFrom;
private bool hasMoreResultsInternal;
Expand All @@ -74,13 +76,15 @@ private ChangeFeedPartitionKeyResultSetIteratorCore(
ContainerInternal container,
ChangeFeedMode mode,
ChangeFeedStartFrom changeFeedStartFrom,
ChangeFeedRequestOptions options)
ChangeFeedRequestOptions options,
FeedRangeEpk feedRangeEpk)
{
this.container = container ?? throw new ArgumentNullException(nameof(container));
this.mode = mode;
this.changeFeedStartFrom = changeFeedStartFrom ?? throw new ArgumentNullException(nameof(changeFeedStartFrom));
this.clientContext = this.container.ClientContext;
this.changeFeedOptions = options;
this.feedRangeEpk = feedRangeEpk;
}

public override bool HasMoreResults => this.hasMoreResultsInternal;
Expand Down Expand Up @@ -140,6 +144,16 @@ public override async Task<ResponseMessage> ReadNextAsync(ITrace trace, Cancella
responseMessage.Headers.ContinuationToken = etag;
this.changeFeedStartFrom = new ChangeFeedStartFromContinuationAndFeedRange(etag, (FeedRangeInternal)this.changeFeedStartFrom.FeedRange);

// Set the FeedRangeMinMax response header.

if (this.feedRangeEpk != null)
{
responseMessage.Headers.FeedRangeDetails = FeedRangeDetail.Create(
minInclusive: this.feedRangeEpk.Range.Min,
maxExclusive: this.feedRangeEpk.Range.Max,
collectionRid: responseMessage.RequestMessage.DocumentServiceRequest.ResourceId);
}

return responseMessage;
}
}
Expand Down
54 changes: 54 additions & 0 deletions Microsoft.Azure.Cosmos/src/ChangeFeed/FeedRangeDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.ChangeFeed
{
/// <summary>
/// The feed range details.
/// </summary>
public class FeedRangeDetail
{
/// <summary>
/// Gets the min inclusive.
/// </summary>
public string MinInclusive { get; private set; }

/// <summary>
/// Gets the max exclusive.
/// </summary>
public string MaxExclusive { get; private set; }

/// <summary>
/// Gets the collection resource id.
/// </summary>
public string CollectionRid { get; private set; }

/// <summary>
/// Creates a new feed range detail.
/// </summary>
/// <param name="minInclusive"></param>
/// <param name="maxExclusive"></param>
/// <param name="collectionRid"></param>
/// <returns>A immutable feed range detail.</returns>
public static FeedRangeDetail Create(string minInclusive, string maxExclusive, string collectionRid)
{
return new FeedRangeDetail(
minInclusive: minInclusive,
maxExclusive: maxExclusive,
collectionRid: collectionRid);
}
/// <summary>
/// The construtor for the feed range detail.
/// </summary>
/// <param name="minInclusive">The minInclusive for the feed range.</param>
/// <param name="maxExclusive">The maxExclusive for the feed range.</param>
/// <param name="collectionRid">The collection resource id for the feed range.</param>
private FeedRangeDetail(string minInclusive, string maxExclusive, string collectionRid)
{
this.MinInclusive = minInclusive;
this.MaxExclusive = maxExclusive;
this.CollectionRid = collectionRid;
}
}
}
9 changes: 9 additions & 0 deletions Microsoft.Azure.Cosmos/src/Headers/Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,5 +457,14 @@ internal static SubStatusCodes GetSubStatusCodes(string value)

return null;
}

/// <summary>
/// Gets the feed range details.
/// </summary>
public virtual ChangeFeed.FeedRangeDetail FeedRangeDetails
{
get;
internal set;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.QueryClient
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Routing;

internal readonly struct ContainerQueryProperties
{
public ContainerQueryProperties(
string resourceId,
IReadOnlyList<Range<string>> effectivePartitionKeyRanges,
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Query.Core.QueryClient
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Routing;
internal readonly struct ContainerQueryProperties
{
public ContainerQueryProperties(
string resourceId,
IReadOnlyList<Range<string>> effectivePartitionKeyRanges,
PartitionKeyDefinition partitionKeyDefinition,
Cosmos.VectorEmbeddingPolicy vectorEmbeddingPolicy,
Cosmos.GeospatialType geospatialType)
{
this.ResourceId = resourceId;
this.EffectiveRangesForPartitionKey = effectivePartitionKeyRanges;
Cosmos.VectorEmbeddingPolicy vectorEmbeddingPolicy,
Cosmos.GeospatialType geospatialType)
{
this.ResourceId = resourceId;
this.EffectiveRangesForPartitionKey = effectivePartitionKeyRanges;
this.PartitionKeyDefinition = partitionKeyDefinition;
this.VectorEmbeddingPolicy = vectorEmbeddingPolicy;
this.GeospatialType = geospatialType;
}

public string ResourceId { get; }

//A PartitionKey has one range when it is a full PartitionKey value.
//It can span many it is a prefix PartitionKey for a sub-partitioned container.
public IReadOnlyList<Range<string>> EffectiveRangesForPartitionKey { get; }
this.VectorEmbeddingPolicy = vectorEmbeddingPolicy;
this.GeospatialType = geospatialType;
}
public string ResourceId { get; }
//A PartitionKey has one range when it is a full PartitionKey value.
//It can span many it is a prefix PartitionKey for a sub-partitioned container.
public IReadOnlyList<Range<string>> EffectiveRangesForPartitionKey { get; }

public PartitionKeyDefinition PartitionKeyDefinition { get; }

public Cosmos.VectorEmbeddingPolicy VectorEmbeddingPolicy { get; }
public Cosmos.VectorEmbeddingPolicy VectorEmbeddingPolicy { get; }

public Cosmos.GeospatialType GeospatialType { get; }
}
public Cosmos.GeospatialType GeospatialType { get; }
}
}
72 changes: 71 additions & 1 deletion Microsoft.Azure.Cosmos/src/Routing/PartitionKeyRangeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ namespace Microsoft.Azure.Cosmos.Routing
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.ChangeFeed.Utils;
using Microsoft.Azure.Cosmos.Common;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Cosmos.Tracing.TraceData;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
using Microsoft.Azure.Documents.Routing;
using Newtonsoft.Json;

internal class PartitionKeyRangeCache : IRoutingMapProvider, ICollectionRoutingMapCache
{
Expand Down Expand Up @@ -81,6 +82,75 @@ public virtual async Task<IReadOnlyList<PartitionKeyRange>> TryGetOverlappingRan
}
}

/// <summary>
/// Gets the overlapping ranges for a list of feed ranges.
/// </summary>
/// <param name="collectionRid"></param>
/// <param name="ranges"></param>
/// <param name="trace"></param>
/// <param name="forceRefresh"></param>
public virtual async Task<IReadOnlyList<PartitionKeyRange>> TryGetOverlappingRangesAsync(
string collectionRid,
IReadOnlyList<Range<string>> ranges,
ITrace trace,
bool forceRefresh = false)
{
List<PartitionKeyRange> partitionKeyRanges = new ();

using (ITrace childTrace = trace.StartChild("Try Get Overlapping Ranges", TraceComponent.Routing, Tracing.TraceLevel.Info))
{
Debug.Assert(ResourceId.TryParse(collectionRid, out ResourceId collectionRidParsed), "Could not parse CollectionRid from ResourceId.");

foreach (Range<string> range in ranges)
{
IReadOnlyList<PartitionKeyRange> overlappingRanges = await this.TryGetOverlappingRangesAsync(
collectionRid: collectionRid,
range: range,
trace: childTrace,
forceRefresh: forceRefresh);

Debug.Assert(overlappingRanges != null, $"There should always be overlapping ranges for {JsonConvert.SerializeObject(range)}.");

partitionKeyRanges.AddRange(overlappingRanges);
}
}

return partitionKeyRanges.AsReadOnly();
}

/// <summary>
/// Gets the overlapping ranges for a list of feed ranges.
/// </summary>
/// <param name="collectionRid"></param>
/// <param name="partitionKey"></param>
/// <param name="trace"></param>
/// <param name="forceRefresh"></param>
public virtual async Task<IReadOnlyList<PartitionKeyRange>> TryGetOverlappingRangesAsync(
string collectionRid,
PartitionKey partitionKey,
ITrace trace,
bool forceRefresh = false)
{
List<PartitionKeyRange> partitionKeyRanges = new ();

using (ITrace childTrace = trace.StartChild("Try Get Overlapping Ranges", TraceComponent.Routing, Tracing.TraceLevel.Info))
{
Debug.Assert(ResourceId.TryParse(collectionRid, out ResourceId collectionRidParsed), "Could not parse CollectionRid from ResourceId.");

CollectionRoutingMap routingMap = await this.TryLookupAsync(
collectionRid: collectionRid,
previousValue: null,
request: null,
trace: childTrace);

Debug.WriteLine($"{nameof(routingMap)} -> {JsonConvert.SerializeObject(routingMap)}");
}

await Task.Delay(TimeSpan.FromSeconds(5));

return partitionKeyRanges.AsReadOnly();
}

public virtual async Task<PartitionKeyRange> TryGetPartitionKeyRangeByIdAsync(
string collectionResourceId,
string partitionKeyRangeId,
Expand Down
Loading
Loading