Query: Fixes split proofing logic for queries with logical partition key #1988
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Query: Fixes split proofing logic for queries with logical partition key
Description
Suppose the partition spans epk range A to E
And the user send a query with partition key that hashes to C
When we query the results the continuation token will look something like:
Now suppose there is a split that creates two partitions A to B and B to E
Now C will map to the partition that goes from B to E
When we run the following code:
https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CrossPartition/PartitionMapper.cs#L68
We are going to hit an exception, since the code looks for a partition to resume from which in this case should be B to E, but we have the value A to E and we are checking to see if a partition matches the start of range (in this case A).
This leads to an exception.
This code path doesn’t happen in the case of non partition key queries, since the call to get target partition key ranges gives the full set of ranges and we always finish reading from the left most partition before moving on to the right most partition.
This fix detects if we are in a single partition scenario and resumes from that partition. The longer term solution is to wire FeedRangeState throughout the query stack (similar to what we have for ChangeFeed: #1978).