Skip to content

Resharding: Route requests to source shard while target is pre-handoff #131306

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

Merged
merged 20 commits into from
Jul 18, 2025

Conversation

ankikuma
Copy link
Contributor

This PR routes DocWriteRequests (index/delete/update requests) that are meant for the target shards, to source shards, when the target shard is not yet ready.

The changes here should also handle bulk requests, because BulkOperation#groupRequestsByShards calls int shardId = docWriteRequest.route(indexRouting); to obtain the shardId. The route() codepath has been modified in this PR to handle resharding scenario.

This PR does not address the following cases:

  1. A request gets routed to the source shard because the coordinating node is not even aware of an ongoing reshard operation.
  2. A request meant for the target shard gets routed to the source shard because coordinating node sees the target shard is not ready. However, this view of the state is found to be stale once the request arrives at the primary shard.

@ankikuma ankikuma added the :Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. label Jul 16, 2025
@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Jul 16, 2025
@ankikuma ankikuma added Team:Distributed Indexing Meta label for Distributed Indexing team >non-issue labels Jul 16, 2025
@ankikuma ankikuma marked this pull request as ready for review July 16, 2025 22:29
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-indexing (Team:Distributed Indexing)

@ankikuma ankikuma requested review from bcully and lkts July 17, 2025 14:36
* @return Updated shardId
*/
protected final int rerouteIfResharding(int shardId) {
if (indexReshardingMetadata != null && indexReshardingMetadata.getSplit().isTargetShard(shardId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we check for indexReshardingMetadata.isSplit()? It's technically possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly we should assert it is split, because I don't know right now what the correct behaviour here would be if it isn't. Good chance that we'll also need some logic here for any other resharding type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i am okay with assert

return (indexReshardingMetadata.getSplit().sourceShard(shardId));
}
}
return (shardId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why brackets? :)

Copy link
Contributor

@bcully bcully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (one comment)

* @return Updated shardId
*/
protected final int rerouteIfResharding(int shardId) {
if (indexReshardingMetadata != null && indexReshardingMetadata.getSplit().isTargetShard(shardId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly we should assert it is split, because I don't know right now what the correct behaviour here would be if it isn't. Good chance that we'll also need some logic here for any other resharding type.

@ankikuma ankikuma enabled auto-merge (squash) July 18, 2025 03:18
@ankikuma ankikuma disabled auto-merge July 18, 2025 12:18
*/
protected final int rerouteIfResharding(int shardId) {
if (indexReshardingMetadata != null && indexReshardingMetadata.getSplit().isTargetShard(shardId)) {
assert indexReshardingMetadata.isSplit() : "Index resharding state is not a split";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be before the line with getSplit()?

@ankikuma ankikuma merged commit a6d6d3e into elastic:main Jul 18, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. >non-issue serverless-linked Added by automation, don't add manually Team:Distributed Indexing Meta label for Distributed Indexing team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants