Skip to content

Commit 69683ad

Browse files
committed
fix
1 parent 27b3df0 commit 69683ad

File tree

2 files changed

+73
-16
lines changed

2 files changed

+73
-16
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/SplitShardCountSummary.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
* Note that in this case no shard-bulk-request is sent to shards 5, 6, 7 and the requests that were meant for these target shards
4848
* are bundled together with and sent to their source shards.
4949
*
50+
* Example 3:
51+
* Suppose we are resharding an index from 4 -> 8 shards. While handling a search request, the coordinator observes
52+
* that target shard 5 is in SPLIT state but target shards 4, 6, 7 are in CLONE/HANDOFF state.
53+
* The coordinator will send shard search requests to all source shards (0, 1, 2, 3) and to all target shards
54+
* that are at least in SPLIT state (5).
55+
* Shard search request sent to source shards 0, 2, 3 has the "reshardSplitShardCountSummary" of 4
56+
* since corresponding target shards (4, 6, 7) have not advanced to SPLIT state.
57+
* Shard search request sent to source shard 1 has the "reshardSplitShardCountSummary" of 8
58+
* since the corresponding target shard 5 is in SPLIT state.
59+
* When a shard search request is executed on the source shard 1, "reshardSplitShardCountSummary" value
60+
* is checked and documents that will be returned by target shard 5 are excluded
61+
* (they are still present in the source shard because the resharding process is not complete).
62+
* All other source shard search requests (0, 2, 3) return all available documents since corresponding target shards
63+
* are not yet available to do that.
64+
*
5065
* A value of 0 indicates an INVALID reshardSplitShardCountSummary. Hence, a request with INVALID reshardSplitShardCountSummary
5166
* will be treated as a Summary mismatch on the source shard node.
5267
*/

server/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public void testOperationRoutingWithResharding() throws IOException {
524524
assertEquals(shardCount, initialSearchShards.size());
525525
for (int i = 0; i < shardCount; i++) {
526526
assertEquals(i, initialSearchShards.get(i).iterator().shardId().id());
527-
assertEquals(shardCount, initialSearchShards.get(i).reshardSplitShardCountSummary());
527+
assertEquals(SplitShardCountSummary.fromInt(shardCount), initialSearchShards.get(i).reshardSplitShardCountSummary());
528528
}
529529

530530
// We are testing a case when there is routing configuration but not for the index in question.
@@ -534,7 +534,7 @@ public void testOperationRoutingWithResharding() throws IOException {
534534
assertEquals(shardCount, initialSearchShardsWithRouting.size());
535535
for (int i = 0; i < shardCount; i++) {
536536
assertEquals(i, initialSearchShardsWithRouting.get(i).iterator().shardId().id());
537-
assertEquals(shardCount, initialSearchShardsWithRouting.get(i).reshardSplitShardCountSummary());
537+
assertEquals(SplitShardCountSummary.fromInt(shardCount), initialSearchShardsWithRouting.get(i).reshardSplitShardCountSummary());
538538
}
539539

540540
var initialWriteableShards = clusterService.operationRouting()
@@ -571,15 +571,21 @@ public void testOperationRoutingWithResharding() throws IOException {
571571
assertEquals(shardCount, searchShardsWithOneShardHandoff.size());
572572
for (int i = 0; i < shardCount; i++) {
573573
assertEquals(i, searchShardsWithOneShardHandoff.get(i).iterator().shardId().id());
574-
assertEquals(shardCount, searchShardsWithOneShardHandoff.get(i).reshardSplitShardCountSummary());
574+
assertEquals(
575+
SplitShardCountSummary.fromInt(shardCount),
576+
searchShardsWithOneShardHandoff.get(i).reshardSplitShardCountSummary()
577+
);
575578
}
576579

577580
var searchShardsWithOneShardHandoffAndRouting = clusterService.operationRouting()
578581
.searchShards(clusterService.state().projectState(projectId), new String[] { indexName }, Map.of("other", Set.of("1")), null);
579582
assertEquals(shardCount, searchShardsWithOneShardHandoffAndRouting.size());
580583
for (int i = 0; i < shardCount; i++) {
581584
assertEquals(i, searchShardsWithOneShardHandoffAndRouting.get(i).iterator().shardId().id());
582-
assertEquals(shardCount, searchShardsWithOneShardHandoffAndRouting.get(i).reshardSplitShardCountSummary());
585+
assertEquals(
586+
SplitShardCountSummary.fromInt(shardCount),
587+
searchShardsWithOneShardHandoffAndRouting.get(i).reshardSplitShardCountSummary()
588+
);
583589
}
584590

585591
var writeableShardsWithOneShardHandoff = clusterService.operationRouting()
@@ -622,12 +628,21 @@ public void testOperationRoutingWithResharding() throws IOException {
622628
}
623629
assertEquals(shardChangingSplitTargetState, searchShardsWithOneShardSplit.get(indexOfShardWithNewState).iterator().shardId().id());
624630
// Since the target shard is in SPLIT state, reshardSplitShardCountSummary is updated for it and the corresponding source shard.
625-
assertEquals(newShardCount, searchShardsWithOneShardSplit.get(indexOfShardWithNewState).reshardSplitShardCountSummary());
631+
assertEquals(
632+
SplitShardCountSummary.fromInt(newShardCount),
633+
searchShardsWithOneShardSplit.get(indexOfShardWithNewState).reshardSplitShardCountSummary()
634+
);
626635
for (int i = 0; i < shardCount; i++) {
627636
if (i == sourceShard) {
628-
assertEquals(newShardCount, searchShardsWithOneShardSplit.get(i).reshardSplitShardCountSummary());
637+
assertEquals(
638+
SplitShardCountSummary.fromInt(newShardCount),
639+
searchShardsWithOneShardSplit.get(i).reshardSplitShardCountSummary()
640+
);
629641
} else {
630-
assertEquals(shardCount, searchShardsWithOneShardSplit.get(i).reshardSplitShardCountSummary());
642+
assertEquals(
643+
SplitShardCountSummary.fromInt(shardCount),
644+
searchShardsWithOneShardSplit.get(i).reshardSplitShardCountSummary()
645+
);
631646
}
632647
}
633648

@@ -642,12 +657,21 @@ public void testOperationRoutingWithResharding() throws IOException {
642657
searchShardsWithOneShardSplitAndRouting.get(indexOfShardWithNewState).iterator().shardId().id()
643658
);
644659
// Since the target shard is in SPLIT state, reshardSplitShardCountSummary is updated for it and the corresponding source shard.
645-
assertEquals(newShardCount, searchShardsWithOneShardSplitAndRouting.get(indexOfShardWithNewState).reshardSplitShardCountSummary());
660+
assertEquals(
661+
SplitShardCountSummary.fromInt(newShardCount),
662+
searchShardsWithOneShardSplitAndRouting.get(indexOfShardWithNewState).reshardSplitShardCountSummary()
663+
);
646664
for (int i = 0; i < shardCount; i++) {
647665
if (i == sourceShard) {
648-
assertEquals(newShardCount, searchShardsWithOneShardSplitAndRouting.get(i).reshardSplitShardCountSummary());
666+
assertEquals(
667+
SplitShardCountSummary.fromInt(newShardCount),
668+
searchShardsWithOneShardSplitAndRouting.get(i).reshardSplitShardCountSummary()
669+
);
649670
} else {
650-
assertEquals(shardCount, searchShardsWithOneShardSplitAndRouting.get(i).reshardSplitShardCountSummary());
671+
assertEquals(
672+
SplitShardCountSummary.fromInt(shardCount),
673+
searchShardsWithOneShardSplitAndRouting.get(i).reshardSplitShardCountSummary()
674+
);
651675
}
652676
}
653677

@@ -685,12 +709,21 @@ public void testOperationRoutingWithResharding() throws IOException {
685709
}
686710
assertEquals(shardChangingSplitTargetState, searchShardsWithOneShardDone.get(indexOfShardWithNewState).iterator().shardId().id());
687711
// Since the target shard is past SPLIT state, reshardSplitShardCountSummary is updated for it and the corresponding source shard.
688-
assertEquals(newShardCount, searchShardsWithOneShardDone.get(indexOfShardWithNewState).reshardSplitShardCountSummary());
712+
assertEquals(
713+
SplitShardCountSummary.fromInt(newShardCount),
714+
searchShardsWithOneShardDone.get(indexOfShardWithNewState).reshardSplitShardCountSummary()
715+
);
689716
for (int i = 0; i < shardCount; i++) {
690717
if (i == sourceShard) {
691-
assertEquals(newShardCount, searchShardsWithOneShardDone.get(i).reshardSplitShardCountSummary());
718+
assertEquals(
719+
SplitShardCountSummary.fromInt(newShardCount),
720+
searchShardsWithOneShardDone.get(i).reshardSplitShardCountSummary()
721+
);
692722
} else {
693-
assertEquals(shardCount, searchShardsWithOneShardDone.get(i).reshardSplitShardCountSummary());
723+
assertEquals(
724+
SplitShardCountSummary.fromInt(shardCount),
725+
searchShardsWithOneShardDone.get(i).reshardSplitShardCountSummary()
726+
);
694727
}
695728
}
696729

@@ -705,12 +738,21 @@ public void testOperationRoutingWithResharding() throws IOException {
705738
searchShardsWithOneShardDoneAndRouting.get(indexOfShardWithNewState).iterator().shardId().id()
706739
);
707740
// Since the target shard is past SPLIT state, reshardSplitShardCountSummary is updated for it and the corresponding source shard.
708-
assertEquals(newShardCount, searchShardsWithOneShardDoneAndRouting.get(indexOfShardWithNewState).reshardSplitShardCountSummary());
741+
assertEquals(
742+
SplitShardCountSummary.fromInt(newShardCount),
743+
searchShardsWithOneShardDoneAndRouting.get(indexOfShardWithNewState).reshardSplitShardCountSummary()
744+
);
709745
for (int i = 0; i < shardCount; i++) {
710746
if (i == sourceShard) {
711-
assertEquals(newShardCount, searchShardsWithOneShardDoneAndRouting.get(i).reshardSplitShardCountSummary());
747+
assertEquals(
748+
SplitShardCountSummary.fromInt(newShardCount),
749+
searchShardsWithOneShardDoneAndRouting.get(i).reshardSplitShardCountSummary()
750+
);
712751
} else {
713-
assertEquals(shardCount, searchShardsWithOneShardDoneAndRouting.get(i).reshardSplitShardCountSummary());
752+
assertEquals(
753+
SplitShardCountSummary.fromInt(shardCount),
754+
searchShardsWithOneShardDoneAndRouting.get(i).reshardSplitShardCountSummary()
755+
);
714756
}
715757
}
716758

0 commit comments

Comments
 (0)