-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Move unpromotable relocations to its own transport action #127330
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
fcofdez
merged 11 commits into
elastic:main
from
fcofdez:ES-10339-unpromotable-relocation-handoff
May 1, 2025
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
37dd524
Move unpromotable relocation to its own transport action
fcofdez 03bbbe7
Update docs/changelog/127330.yaml
fcofdez 64cce51
Merge remote-tracking branch 'origin/main' into ES-10339-unpromotable…
fcofdez 9ef9621
Use cleanupOnly listener instead
fcofdez 7aa5332
Revert "Use cleanupOnly listener instead"
fcofdez c691b69
Use cleanupOnly listener instead
fcofdez 93cc8aa
More changes...
fcofdez 9758d09
Merge remote-tracking branch 'origin/main' into ES-10339-unpromotable…
fcofdez 03d52fb
Add unpromotable transport action implementation for tests
fcofdez e57b8f0
Merge remote-tracking branch 'origin/main' into ES-10339-unpromotable…
fcofdez 48bde1a
Merge remote-tracking branch 'origin/main' into ES-10339-unpromotable…
fcofdez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 127330 | ||
| summary: Move unpromotable relocations to its own transport action | ||
| area: Recovery | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...c/main/java/org/elasticsearch/indices/recovery/StatelessUnpromotableRelocationAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.indices.recovery; | ||
|
|
||
| import org.elasticsearch.action.ActionRequest; | ||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.action.ActionType; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| public class StatelessUnpromotableRelocationAction { | ||
|
|
||
| public static final ActionType<ActionResponse.Empty> TYPE = new ActionType<>( | ||
| "internal:index/shard/recovery/stateless_unpromotable_relocation" | ||
| ); | ||
|
|
||
| public static class Request extends ActionRequest { | ||
| private final long recoveryId; | ||
| private final ShardId shardId; | ||
| private final String targetAllocationId; | ||
| private final long clusterStateVersion; | ||
|
|
||
| public Request(long recoveryId, ShardId shardId, String targetAllocationId, long clusterStateVersion) { | ||
| this.recoveryId = recoveryId; | ||
| this.shardId = shardId; | ||
| this.targetAllocationId = targetAllocationId; | ||
| this.clusterStateVersion = clusterStateVersion; | ||
| } | ||
|
|
||
| public Request(StreamInput in) throws IOException { | ||
| super(in); | ||
| recoveryId = in.readVLong(); | ||
| shardId = new ShardId(in); | ||
| targetAllocationId = in.readString(); | ||
| clusterStateVersion = in.readVLong(); | ||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeVLong(recoveryId); | ||
| shardId.writeTo(out); | ||
| out.writeString(targetAllocationId); | ||
| out.writeVLong(clusterStateVersion); | ||
| } | ||
|
|
||
| public long getRecoveryId() { | ||
| return recoveryId; | ||
| } | ||
|
|
||
| public ShardId getShardId() { | ||
| return shardId; | ||
| } | ||
|
|
||
| public long getClusterStateVersion() { | ||
| return clusterStateVersion; | ||
| } | ||
|
|
||
| public String getTargetAllocationId() { | ||
| return targetAllocationId; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Request request = (Request) o; | ||
| return recoveryId == request.recoveryId | ||
| && clusterStateVersion == request.clusterStateVersion | ||
| && Objects.equals(shardId, request.shardId) | ||
| && Objects.equals(targetAllocationId, request.targetAllocationId); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(recoveryId, shardId, targetAllocationId, clusterStateVersion); | ||
| } | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
...t/java/org/elasticsearch/indices/recovery/StatelessUnpromotableRelocationActionTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.indices.recovery; | ||
|
|
||
| import org.elasticsearch.common.UUIDs; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.index.shard.ShardIdTests; | ||
| import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class StatelessUnpromotableRelocationActionTests extends AbstractWireSerializingTestCase< | ||
| StatelessUnpromotableRelocationAction.Request> { | ||
| @Override | ||
| protected Writeable.Reader<StatelessUnpromotableRelocationAction.Request> instanceReader() { | ||
| return StatelessUnpromotableRelocationAction.Request::new; | ||
| } | ||
|
|
||
| @Override | ||
| protected StatelessUnpromotableRelocationAction.Request createTestInstance() { | ||
| return new StatelessUnpromotableRelocationAction.Request( | ||
| randomNonNegativeLong(), | ||
| new ShardId(randomIdentifier(), UUIDs.randomBase64UUID(), randomIntBetween(0, 99)), | ||
| randomUUID(), | ||
| randomNonNegativeLong() | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected StatelessUnpromotableRelocationAction.Request mutateInstance(StatelessUnpromotableRelocationAction.Request instance) | ||
| throws IOException { | ||
| return switch (between(0, 3)) { | ||
| case 0 -> new StatelessUnpromotableRelocationAction.Request( | ||
| randomValueOtherThan(instance.getRecoveryId(), ESTestCase::randomNonNegativeLong), | ||
| instance.getShardId(), | ||
| instance.getTargetAllocationId(), | ||
| instance.getClusterStateVersion() | ||
| ); | ||
| case 1 -> new StatelessUnpromotableRelocationAction.Request( | ||
| instance.getRecoveryId(), | ||
| ShardIdTests.mutate(instance.getShardId()), | ||
| instance.getTargetAllocationId(), | ||
| instance.getClusterStateVersion() | ||
| ); | ||
| case 2 -> new StatelessUnpromotableRelocationAction.Request( | ||
| instance.getRecoveryId(), | ||
| instance.getShardId(), | ||
| randomValueOtherThan(instance.getTargetAllocationId(), ESTestCase::randomUUID), | ||
| instance.getClusterStateVersion() | ||
| ); | ||
| case 3 -> new StatelessUnpromotableRelocationAction.Request( | ||
| instance.getRecoveryId(), | ||
| instance.getShardId(), | ||
| instance.getTargetAllocationId(), | ||
| randomValueOtherThan(instance.getClusterStateVersion(), ESTestCase::randomNonNegativeLong) | ||
| ); | ||
| default -> throw new AssertionError("Illegal randomisation branch"); | ||
| }; | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
Looks like this was added here, I am also not sure I understand why, perhaps @kingherc remember and can confirm that the assertion is not significant?
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.
Not out of the top of my head. But going back to the code, I see we've made a special branch in
PeerRecoveryTargetService#doRecovery()withif (indexShard.routingEntry().isPromotableToPrimary() == false) {for unpromotables that basically quick skips all recovery stages, and closes the RecoveryRef as well. So the point of the assertion at the time was that there should be no other coordination needed for unpromotables to justify getting the RecoveryRef.Seeing though that now this PR introduces some sort of coordination between unpromotables, it probably makes to remove the assertion.
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.
(I did not fully review this PR, but feel free to tell me if I should)