Skip to content

Commit c704377

Browse files
ealsurj82w
andauthored
Query: Fixes handling of pipeline execution on partition merge (#2531)
* fix * fixing inmemorycontainer * fixing merge test * undo small change * OrderBy fix too * Correct orderby handling * more tests * text Co-authored-by: j82w <[email protected]>
1 parent 602657e commit c704377

File tree

5 files changed

+211
-24
lines changed

5 files changed

+211
-24
lines changed

Microsoft.Azure.Cosmos/src/Pagination/CrossPartitionRangePageAsyncEnumerator.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,21 @@ public async ValueTask<bool> MoveNextAsync(ITrace trace)
184184
error: new Microsoft.Azure.Documents.Error { Code = "SDK_invariant_violated_4795CC37", Message = errorMessage });
185185
}
186186

187-
foreach (FeedRangeInternal childRange in childRanges)
187+
if (childRanges.Count == 1)
188188
{
189-
PartitionRangePageAsyncEnumerator<TPage, TState> childPaginator = this.createPartitionRangeEnumerator(
190-
new FeedRangeState<TState>(childRange, currentPaginator.FeedRangeState.State));
191-
enumerators.Enqueue(childPaginator);
189+
// On a merge, the 410/1002 results in a single parent
190+
// We maintain the current enumerator's range and let the RequestInvokerHandler logic kick in
191+
enumerators.Enqueue(currentPaginator);
192+
}
193+
else
194+
{
195+
// Split
196+
foreach (FeedRangeInternal childRange in childRanges)
197+
{
198+
PartitionRangePageAsyncEnumerator<TPage, TState> childPaginator = this.createPartitionRangeEnumerator(
199+
new FeedRangeState<TState>(childRange, currentPaginator.FeedRangeState.State));
200+
enumerators.Enqueue(childPaginator);
201+
}
192202
}
193203

194204
// Recursively retry

Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CrossPartition/OrderBy/OrderByCrossPartitionQueryPipelineStage.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,38 @@ private async ValueTask<bool> MoveNextAsync_InitializeAsync_HandleSplitAsync(
319319
error: new Microsoft.Azure.Documents.Error { Code = "SDK_invariant_violated_82086B2D", Message = errorMessage });
320320
}
321321

322-
foreach (FeedRangeInternal childRange in childRanges)
322+
if (childRanges.Count == 1)
323323
{
324-
this.cancellationToken.ThrowIfCancellationRequested();
325-
324+
// On a merge, the 410/1002 results in a single parent
325+
// We maintain the current enumerator's range and let the RequestInvokerHandler logic kick in
326326
OrderByQueryPartitionRangePageAsyncEnumerator childPaginator = new OrderByQueryPartitionRangePageAsyncEnumerator(
327327
this.documentContainer,
328328
uninitializedEnumerator.SqlQuerySpec,
329-
new FeedRangeState<QueryState>(childRange, uninitializedEnumerator.StartOfPageState),
329+
new FeedRangeState<QueryState>(uninitializedEnumerator.FeedRangeState.FeedRange, uninitializedEnumerator.StartOfPageState),
330330
partitionKey: null,
331331
uninitializedEnumerator.QueryPaginationOptions,
332332
uninitializedEnumerator.Filter,
333333
this.cancellationToken);
334334
this.uninitializedEnumeratorsAndTokens.Enqueue((childPaginator, token));
335335
}
336+
else
337+
{
338+
// Split
339+
foreach (FeedRangeInternal childRange in childRanges)
340+
{
341+
this.cancellationToken.ThrowIfCancellationRequested();
342+
343+
OrderByQueryPartitionRangePageAsyncEnumerator childPaginator = new OrderByQueryPartitionRangePageAsyncEnumerator(
344+
this.documentContainer,
345+
uninitializedEnumerator.SqlQuerySpec,
346+
new FeedRangeState<QueryState>(childRange, uninitializedEnumerator.StartOfPageState),
347+
partitionKey: null,
348+
uninitializedEnumerator.QueryPaginationOptions,
349+
uninitializedEnumerator.Filter,
350+
this.cancellationToken);
351+
this.uninitializedEnumeratorsAndTokens.Enqueue((childPaginator, token));
352+
}
353+
}
336354

337355
// Recursively retry
338356
return await this.MoveNextAsync(trace);

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/TraceWriterBaselineTests.ScenariosAsync.xml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@
111111
│ └── Read Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
112112
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) ReadFeed-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
113113
│ └── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
114-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
114+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
115115
│ └── Read Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
116116
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) ReadFeed-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
117117
│ └── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
118-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
118+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
119119
│ └── Read Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
120120
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) ReadFeed-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
121121
│ └── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
122-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
122+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
123123
│ └── Read Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
124124
└── MoveNextAsync(00000000-0000-0000-0000-000000000000) ReadFeed-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
125125
└── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
@@ -1182,7 +1182,7 @@
11821182
"duration in milliseconds": 0,
11831183
"children": [
11841184
{
1185-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
1185+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
11861186
"id": "00000000-0000-0000-0000-000000000000",
11871187
"caller info": {
11881188
"member": "MemberName",
@@ -1232,7 +1232,7 @@
12321232
"duration in milliseconds": 0,
12331233
"children": [
12341234
{
1235-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
1235+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
12361236
"id": "00000000-0000-0000-0000-000000000000",
12371237
"caller info": {
12381238
"member": "MemberName",
@@ -1282,7 +1282,7 @@
12821282
"duration in milliseconds": 0,
12831283
"children": [
12841284
{
1285-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
1285+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
12861286
"id": "00000000-0000-0000-0000-000000000000",
12871287
"caller info": {
12881288
"member": "MemberName",
@@ -1401,7 +1401,7 @@
14011401
│ └── Change Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14021402
├── ChangeFeed MoveNextAsync(00000000-0000-0000-0000-000000000000) ChangeFeed-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14031403
│ └── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
1404-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
1404+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14051405
│ └── Change Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14061406
├── ChangeFeed MoveNextAsync(00000000-0000-0000-0000-000000000000) ChangeFeed-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14071407
│ └── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
@@ -1429,7 +1429,7 @@
14291429
│ └── [BF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14301430
│ └── Change Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14311431
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
1432-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
1432+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14331433
│ └── Change Feed Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14341434
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
14351435
│ └── [7F-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,9F-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
@@ -1796,7 +1796,7 @@
17961796
"duration in milliseconds": 0,
17971797
"children": [
17981798
{
1799-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
1799+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
18001800
"id": "00000000-0000-0000-0000-000000000000",
18011801
"caller info": {
18021802
"member": "MemberName",
@@ -2142,7 +2142,7 @@
21422142
"duration in milliseconds": 0,
21432143
"children": [
21442144
{
2145-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
2145+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
21462146
"id": "00000000-0000-0000-0000-000000000000",
21472147
"caller info": {
21482148
"member": "MemberName",
@@ -2321,10 +2321,10 @@
23212321
│ └── [BF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23222322
│ └── Query Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23232323
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
2324-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
2324+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23252325
│ └── Query Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23262326
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
2327-
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
2327+
│ └── [DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23282328
│ └── Query Transport(00000000-0000-0000-0000-000000000000) Transport-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23292329
├── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
23302330
└── MoveNextAsync(00000000-0000-0000-0000-000000000000) Pagination-Component MemberName@FilePath:42 12:00:00:000 0.00 milliseconds
@@ -2931,7 +2931,7 @@
29312931
"duration in milliseconds": 0,
29322932
"children": [
29332933
{
2934-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
2934+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
29352935
"id": "00000000-0000-0000-0000-000000000000",
29362936
"caller info": {
29372937
"member": "MemberName",
@@ -2968,7 +2968,7 @@
29682968
"duration in milliseconds": 0,
29692969
"children": [
29702970
{
2971-
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,) move next",
2971+
"name": "[DF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF,FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF) move next",
29722972
"id": "00000000-0000-0000-0000-000000000000",
29732973
"caller info": {
29742974
"member": "MemberName",

0 commit comments

Comments
 (0)