-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Do not use split shards for search and refresh if they are not ready #132042
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
Changes from all commits
4f9584f
4037ec4
decc2a9
6b23bf3
2e612be
77a3ae2
6ae508a
820ce80
96a0e1d
328bd1b
2bec0ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
import org.elasticsearch.cluster.ProjectState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.IndexReshardingMetadata; | ||
import org.elasticsearch.cluster.metadata.IndexReshardingState; | ||
import org.elasticsearch.cluster.metadata.ProjectMetadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.common.Strings; | ||
|
@@ -26,6 +28,7 @@ | |
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
@@ -112,6 +115,10 @@ public List<ShardIterator> searchShards( | |
return res; | ||
} | ||
|
||
public Iterator<IndexShardRoutingTable> allWritableShards(ProjectState projectState, String index) { | ||
return allWriteAddressableShards(projectState, index); | ||
} | ||
|
||
public static ShardIterator getShards(RoutingTable routingTable, ShardId shardId) { | ||
final IndexShardRoutingTable shard = routingTable.shardRoutingTable(shardId); | ||
return shard.activeInitializingShardsRandomIt(); | ||
|
@@ -125,7 +132,7 @@ private static Set<IndexShardRoutingTable> computeTargetedShards( | |
// we use set here and not list since we might get duplicates | ||
final Set<IndexShardRoutingTable> set = new HashSet<>(); | ||
if (routing == null || routing.isEmpty()) { | ||
collectTargetShardsNoRouting(projectState.routingTable(), concreteIndices, set); | ||
collectTargetShardsNoRouting(projectState, concreteIndices, set); | ||
} else { | ||
collectTargetShardsWithRouting(projectState, concreteIndices, routing, set); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this branch resolving target shards to source shards before split? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is handled inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but what about this codepath in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should, thanks for catching that. |
||
} | ||
|
@@ -147,20 +154,64 @@ private static void collectTargetShardsWithRouting( | |
indexRouting.collectSearchShards(r, s -> set.add(RoutingTable.shardRoutingTable(indexRoutingTable, s))); | ||
} | ||
} else { | ||
for (int i = 0; i < indexRoutingTable.size(); i++) { | ||
set.add(indexRoutingTable.shard(i)); | ||
Iterator<IndexShardRoutingTable> iterator = allSearchAddressableShards(projectState, index); | ||
while (iterator.hasNext()) { | ||
set.add(iterator.next()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void collectTargetShardsNoRouting(RoutingTable routingTable, String[] concreteIndices, Set<IndexShardRoutingTable> set) { | ||
private static void collectTargetShardsNoRouting(ProjectState projectState, String[] concreteIndices, Set<IndexShardRoutingTable> set) { | ||
for (String index : concreteIndices) { | ||
final IndexRoutingTable indexRoutingTable = indexRoutingTable(routingTable, index); | ||
for (int i = 0; i < indexRoutingTable.size(); i++) { | ||
set.add(indexRoutingTable.shard(i)); | ||
Iterator<IndexShardRoutingTable> iterator = allSearchAddressableShards(projectState, index); | ||
while (iterator.hasNext()) { | ||
set.add(iterator.next()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns an iterator of shards that can possibly serve searches. A shard may not be addressable during processes like resharding. | ||
* This logic is not related to shard state or a recovery process. A shard returned here may f.e. be unassigned. | ||
*/ | ||
private static Iterator<IndexShardRoutingTable> allSearchAddressableShards(ProjectState projectState, String index) { | ||
return allShardsExceptSplitTargetsInStateBefore(projectState, index, IndexReshardingState.Split.TargetShardState.SPLIT); | ||
} | ||
|
||
/** | ||
* Returns an iterator of shards that can possibly serve writes. A shard may not be addressable during processes like resharding. | ||
* This logic is not related to shard state or a recovery process. A shard returned here may f.e. be unassigned. | ||
*/ | ||
private static Iterator<IndexShardRoutingTable> allWriteAddressableShards(ProjectState projectState, String index) { | ||
return allShardsExceptSplitTargetsInStateBefore(projectState, index, IndexReshardingState.Split.TargetShardState.HANDOFF); | ||
} | ||
|
||
/** | ||
* Filters shards based on their state in resharding metadata. If resharing metadata is not present returns all shards. | ||
*/ | ||
private static Iterator<IndexShardRoutingTable> allShardsExceptSplitTargetsInStateBefore( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment here so the reader knows it is associated with resharding and not to be confused with the split API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that class level documentation on |
||
ProjectState projectState, | ||
String index, | ||
IndexReshardingState.Split.TargetShardState targetShardState | ||
) { | ||
final IndexRoutingTable indexRoutingTable = indexRoutingTable(projectState.routingTable(), index); | ||
final IndexMetadata indexMetadata = indexMetadata(projectState.metadata(), index); | ||
if (indexMetadata.getReshardingMetadata() == null) { | ||
return indexRoutingTable.allShards().iterator(); | ||
} | ||
|
||
final IndexReshardingMetadata indexReshardingMetadata = indexMetadata.getReshardingMetadata(); | ||
assert indexReshardingMetadata.isSplit(); | ||
final IndexReshardingState.Split splitState = indexReshardingMetadata.getSplit(); | ||
|
||
var shards = new ArrayList<IndexShardRoutingTable>(); | ||
for (int i = 0; i < indexRoutingTable.size(); i++) { | ||
if (splitState.isTargetShard(i) == false || splitState.targetStateAtLeast(i, targetShardState)) { | ||
shards.add(indexRoutingTable.shard(i)); | ||
} | ||
} | ||
return shards.iterator(); | ||
} | ||
|
||
private ShardIterator preferenceActiveShardIterator( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handles refresh and flush APIs.