-
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
Changes from 2 commits
37dd524
03bbbe7
64cce51
9ef9621
7aa5332
c691b69
93cc8aa
9758d09
03d52fb
e57b8f0
48bde1a
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 127330 | ||
| summary: Move unpromotable relocations to its own transport action | ||
| area: Recovery | ||
| type: enhancement | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,7 +167,6 @@ public RecoveryRef getRecoverySafe(long id, ShardId shardId) { | |
| throw new IndexShardClosedException(shardId); | ||
| } | ||
| assert recoveryRef.target().shardId().equals(shardId); | ||
| assert recoveryRef.target().indexShard().routingEntry().isPromotableToPrimary(); | ||
|
Contributor
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.
Contributor
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. Not out of the top of my head. But going back to the code, I see we've made a special branch in Seeing though that now this PR introduces some sort of coordination between unpromotables, it probably makes to remove the assertion.
Contributor
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 did not fully review this PR, but feel free to tell me if I should) |
||
| return recoveryRef; | ||
| } | ||
|
|
||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } |
| 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"); | ||
| }; | ||
| } | ||
| } |
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 would think this releases the recovery monitor and the recovery-ref too soon? My intuition would be that it should only be done when the action completes?
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.
My understanding is that the RecoveryTarget would be retained until the recovery is marked as done (since the initial refCount=1 from the AbstractRefCounted corresponds to that decRef). But just to be on the safe side I've reverted to the previous behaviour that would release the RecoveryRef once the action returns.