-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ILM] Add unfollow action #36970
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
[ILM] Add unfollow action #36970
Changes from 14 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
c0fc17e
[ILM] Add unfollow action
martijnvg f9f530e
Replaced ccr / ilm integ test with multi cluster integ test and
martijnvg 80bb2ef
Fixed tests
martijnvg a265c2a
Added more tests
martijnvg e281b03
Rename class to WaitForIndexingCompleteStep
gwbrown 07f0136
Factor "ccr" out into constant
gwbrown 509718c
Add note about leader index to error message
gwbrown 974bb8b
Factor out mocking into methods
gwbrown 97df36b
Merge branch 'master' into pr/36970
gwbrown 37bd0ef
Fix error message in test
gwbrown 94dc951
[WIP] Add rollover-based test case
gwbrown e996f83
Merge branch 'master' into pr/36970
gwbrown 3949445
Decreased read_poll_timeout from 60 seconds to 1 second.
martijnvg 0ef7002
Adjusted testGetNextActionName() test
martijnvg 6bb4055
Merge branch 'master' into pr/36970
gwbrown 2d368ab
More informative message when following is paused
gwbrown 7485773
Remove index settings from step info
gwbrown d96ebbb
Javadoc for UnfollowAction
gwbrown 464c256
UnfollowAction hashcode
gwbrown 5d63a5a
Handle deleted indices in WaitForIndexingComplete
gwbrown f63e73d
added assertion messages
martijnvg deac47a
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg 886a3f5
Moved pause follower index, close follower index and
martijnvg 2b60e54
Remove unused imports
gwbrown 6d0e236
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg 533bc4f
Allow UnfollowAction in Warm and Cold phases
gwbrown 731d8d2
Add Unfollow action to HLRC
gwbrown 67f970e
added docs for the unfollow action
martijnvg 272b8d6
added wait for yellow step. That will run after open index step,
martijnvg ea93eda
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg e9b252e
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg 0416490
docs iter
martijnvg 443fc4a
changed WaitForYellowStep to be a AsyncWaitStep
martijnvg 5abf557
take into account no IndexRoutingTable
martijnvg caa13ce
Add Unfollow to Warm/Cold phase ordering test
gwbrown 7f521e8
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg 5d3d661
OpenFollowerIndexStep cannot extend from AbstractUnfollowIndexStep,
martijnvg f7e74d4
Add `indexing_complete` setting to Wait step info
gwbrown 7c1749b
Added Unfollow to the Actions docs ToC
gwbrown fcf34e6
Switch Info to hardcoded false
gwbrown c02f8cb
fixed checkstyle violation
martijnvg a9b2663
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg bb67cdb
Merge branch 'master' into pr/36970
gwbrown 3ee6298
Fix a couple tests
gwbrown f1c05bd
Run SetPriority before Unfollow
gwbrown ca0d2cc
Merge branch 'master' into pr/36970
gwbrown 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
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
97 changes: 97 additions & 0 deletions
97
...plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/UnfollowAction.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,97 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| package org.elasticsearch.xpack.core.indexlifecycle; | ||
|
|
||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.xcontent.ObjectParser; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public final class UnfollowAction implements LifecycleAction { | ||
|
|
||
| public static final String NAME = "unfollow"; | ||
| public static final String CCR_METADATA_KEY = "ccr"; | ||
|
|
||
| public UnfollowAction() {} | ||
|
|
||
| @Override | ||
| public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) { | ||
| StepKey indexingComplete = new StepKey(phase, NAME, WaitForIndexingCompleteStep.NAME); | ||
| StepKey waitForFollowShardTasks = new StepKey(phase, NAME, WaitForFollowShardTasksStep.NAME); | ||
| StepKey unfollowIndex = new StepKey(phase, NAME, UnfollowFollowIndexStep.NAME); | ||
|
|
||
| WaitForIndexingCompleteStep step1 = new WaitForIndexingCompleteStep(indexingComplete, waitForFollowShardTasks); | ||
| WaitForFollowShardTasksStep step2 = new WaitForFollowShardTasksStep(waitForFollowShardTasks, unfollowIndex, client); | ||
| UnfollowFollowIndexStep step3 = new UnfollowFollowIndexStep(unfollowIndex, nextStepKey, client); | ||
| return Arrays.asList(step1, step2, step3); | ||
| } | ||
|
|
||
| @Override | ||
| public List<StepKey> toStepKeys(String phase) { | ||
| StepKey indexingCompleteStep = new StepKey(phase, NAME, WaitForIndexingCompleteStep.NAME); | ||
| StepKey waitForFollowShardTasksStep = new StepKey(phase, NAME, WaitForFollowShardTasksStep.NAME); | ||
| StepKey unfollowIndexStep = new StepKey(phase, NAME, UnfollowFollowIndexStep.NAME); | ||
| return Arrays.asList(indexingCompleteStep, waitForFollowShardTasksStep, unfollowIndexStep); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSafeAction() { | ||
| // There are no settings to change, so therefor this action should be safe: | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String getWriteableName() { | ||
| return NAME; | ||
| } | ||
|
|
||
| public UnfollowAction(StreamInput in) throws IOException {} | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException {} | ||
|
|
||
| private static final ObjectParser<UnfollowAction, Void> PARSER = new ObjectParser<>(NAME, UnfollowAction::new); | ||
|
|
||
| public static UnfollowAction parse(XContentParser parser) { | ||
| return PARSER.apply(parser, null); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return 1; | ||
gwbrown marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (obj == null) { | ||
| return false; | ||
| } | ||
| if (obj.getClass() != getClass()) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return Strings.toString(this); | ||
dakrone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
85 changes: 85 additions & 0 deletions
85
...re/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/UnfollowFollowIndexStep.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,85 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| package org.elasticsearch.xpack.core.indexlifecycle; | ||
|
|
||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; | ||
| import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
| import org.elasticsearch.xpack.core.ccr.action.PauseFollowAction; | ||
| import org.elasticsearch.xpack.core.ccr.action.UnfollowAction; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static org.elasticsearch.xpack.core.indexlifecycle.UnfollowAction.CCR_METADATA_KEY; | ||
|
|
||
| final class UnfollowFollowIndexStep extends AsyncActionStep { | ||
|
|
||
| static final String NAME = "unfollow-index"; | ||
|
|
||
| UnfollowFollowIndexStep(StepKey key, StepKey nextStepKey, Client client) { | ||
| super(key, nextStepKey, client); | ||
| } | ||
|
|
||
| @Override | ||
| public void performAction(IndexMetaData indexMetaData, ClusterState currentClusterState, Listener listener) { | ||
| String followerIndex = indexMetaData.getIndex().getName(); | ||
| Map<String, String> customIndexMetadata = indexMetaData.getCustomData(CCR_METADATA_KEY); | ||
| if (customIndexMetadata == null) { | ||
| listener.onResponse(true); | ||
| return; | ||
| } | ||
|
|
||
| pauseFollowerIndex(followerIndex, listener); | ||
| } | ||
|
|
||
| void pauseFollowerIndex(final String followerIndex, final Listener listener) { | ||
dakrone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| PauseFollowAction.Request request = new PauseFollowAction.Request(followerIndex); | ||
| getClient().execute(PauseFollowAction.INSTANCE, request, ActionListener.wrap( | ||
| r -> { | ||
| assert r.isAcknowledged(); | ||
dakrone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| closeFollowerIndex(followerIndex, listener); | ||
| }, | ||
| listener::onFailure | ||
| )); | ||
| } | ||
|
|
||
| void closeFollowerIndex(final String followerIndex, final Listener listener) { | ||
| CloseIndexRequest closeIndexRequest = new CloseIndexRequest(followerIndex); | ||
| getClient().admin().indices().close(closeIndexRequest, ActionListener.wrap( | ||
| acknowledgedResponse -> { | ||
| assert acknowledgedResponse.isAcknowledged(); | ||
dakrone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| unfollow(followerIndex, listener); | ||
| }, | ||
| listener::onFailure) | ||
| ); | ||
| } | ||
|
|
||
| void unfollow(final String followerIndex, final Listener listener) { | ||
| UnfollowAction.Request request = new UnfollowAction.Request(followerIndex); | ||
| getClient().execute(UnfollowAction.INSTANCE, request, ActionListener.wrap( | ||
| r -> { | ||
| assert r.isAcknowledged(); | ||
dakrone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| openIndex(followerIndex, listener); | ||
| }, | ||
| listener::onFailure | ||
| )); | ||
| } | ||
|
|
||
| void openIndex(final String index, final Listener listener) { | ||
| OpenIndexRequest request = new OpenIndexRequest(index); | ||
| getClient().admin().indices().open(request, ActionListener.wrap( | ||
| openIndexResponse -> { | ||
| assert openIndexResponse.isAcknowledged(); | ||
dakrone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| listener.onResponse(true); | ||
| }, | ||
| listener::onFailure | ||
| )); | ||
| } | ||
|
|
||
| } | ||
176 changes: 176 additions & 0 deletions
176
...rc/main/java/org/elasticsearch/xpack/core/indexlifecycle/WaitForFollowShardTasksStep.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,176 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| package org.elasticsearch.xpack.core.indexlifecycle; | ||
|
|
||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus; | ||
| import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.elasticsearch.xpack.core.indexlifecycle.UnfollowAction.CCR_METADATA_KEY; | ||
|
|
||
| final class WaitForFollowShardTasksStep extends AsyncWaitStep { | ||
|
|
||
| static final String NAME = "wait-for-follow-shard-tasks"; | ||
|
|
||
| WaitForFollowShardTasksStep(StepKey key, StepKey nextStepKey, Client client) { | ||
| super(key, nextStepKey, client); | ||
| } | ||
|
|
||
| @Override | ||
| public void evaluateCondition(IndexMetaData indexMetaData, Listener listener) { | ||
| Map<String, String> customIndexMetadata = indexMetaData.getCustomData(CCR_METADATA_KEY); | ||
| if (customIndexMetadata == null) { | ||
| listener.onResponse(true, null); | ||
| return; | ||
| } | ||
|
|
||
| FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest(); | ||
| request.setIndices(new String[]{indexMetaData.getIndex().getName()}); | ||
| getClient().execute(FollowStatsAction.INSTANCE, request, | ||
| ActionListener.wrap(r -> handleResponse(r, listener), listener::onFailure)); | ||
| } | ||
|
|
||
| void handleResponse(FollowStatsAction.StatsResponses responses, Listener listener) { | ||
| List<ShardFollowNodeTaskStatus> unSyncedShardFollowStatuses = responses.getStatsResponses() | ||
| .stream() | ||
| .map(FollowStatsAction.StatsResponse::status) | ||
| .filter(shardFollowStatus -> shardFollowStatus.leaderGlobalCheckpoint() != shardFollowStatus.followerGlobalCheckpoint()) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| // Follow stats api needs to return stats for follower index and all shard follow tasks should be synced: | ||
| boolean conditionMet = responses.getStatsResponses().size() > 0 && unSyncedShardFollowStatuses.isEmpty(); | ||
gwbrown marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (conditionMet) { | ||
| listener.onResponse(true, null); | ||
| } else { | ||
| List<Info.ShardFollowTaskInfo> shardFollowTaskInfos = unSyncedShardFollowStatuses | ||
| .stream() | ||
| .map(status -> new Info.ShardFollowTaskInfo(status.followerIndex(), status.getShardId(), | ||
| status.leaderGlobalCheckpoint(), status.followerGlobalCheckpoint())) | ||
| .collect(Collectors.toList()); | ||
| listener.onResponse(false, new Info(shardFollowTaskInfos)); | ||
| } | ||
| } | ||
|
|
||
| static final class Info implements ToXContentObject { | ||
|
|
||
| static final ParseField SHARD_FOLLOW_TASKS = new ParseField("shard_follow_tasks"); | ||
| static final ParseField MESSAGE = new ParseField("message"); | ||
|
|
||
| private final List<ShardFollowTaskInfo> shardFollowTaskInfos; | ||
|
|
||
| Info(List<ShardFollowTaskInfo> shardFollowTaskInfos) { | ||
| this.shardFollowTaskInfos = shardFollowTaskInfos; | ||
| } | ||
|
|
||
| List<ShardFollowTaskInfo> getShardFollowTaskInfos() { | ||
| return shardFollowTaskInfos; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(SHARD_FOLLOW_TASKS.getPreferredName(), shardFollowTaskInfos); | ||
| String message = "Waiting for [" + shardFollowTaskInfos.size() + "] shard follow tasks to be in sync"; | ||
| builder.field(MESSAGE.getPreferredName(), message); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Info info = (Info) o; | ||
| return Objects.equals(shardFollowTaskInfos, info.shardFollowTaskInfos); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(shardFollowTaskInfos); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return Strings.toString(this); | ||
| } | ||
|
|
||
| static final class ShardFollowTaskInfo implements ToXContentObject { | ||
|
|
||
| static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index"); | ||
| static final ParseField SHARD_ID_FIELD = new ParseField("shard_id"); | ||
| static final ParseField LEADER_GLOBAL_CHECKPOINT_FIELD = new ParseField("leader_global_checkpoint"); | ||
| static final ParseField FOLLOWER_GLOBAL_CHECKPOINT_FIELD = new ParseField("follower_global_checkpoint"); | ||
|
|
||
| private final String followerIndex; | ||
| private final int shardId; | ||
| private final long leaderGlobalCheckpoint; | ||
| private final long followerGlobalCheckpoint; | ||
|
|
||
| ShardFollowTaskInfo(String followerIndex, int shardId, long leaderGlobalCheckpoint, long followerGlobalCheckpoint) { | ||
| this.followerIndex = followerIndex; | ||
| this.shardId = shardId; | ||
| this.leaderGlobalCheckpoint = leaderGlobalCheckpoint; | ||
| this.followerGlobalCheckpoint = followerGlobalCheckpoint; | ||
| } | ||
|
|
||
| String getFollowerIndex() { | ||
| return followerIndex; | ||
| } | ||
|
|
||
|
|
||
| int getShardId() { | ||
| return shardId; | ||
| } | ||
|
|
||
| long getLeaderGlobalCheckpoint() { | ||
| return leaderGlobalCheckpoint; | ||
| } | ||
|
|
||
| long getFollowerGlobalCheckpoint() { | ||
| return followerGlobalCheckpoint; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(FOLLOWER_INDEX_FIELD.getPreferredName(), followerIndex); | ||
| builder.field(SHARD_ID_FIELD.getPreferredName(), shardId); | ||
| builder.field(LEADER_GLOBAL_CHECKPOINT_FIELD.getPreferredName(), leaderGlobalCheckpoint); | ||
| builder.field(FOLLOWER_GLOBAL_CHECKPOINT_FIELD.getPreferredName(), followerGlobalCheckpoint); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| ShardFollowTaskInfo that = (ShardFollowTaskInfo) o; | ||
| return shardId == that.shardId && | ||
| leaderGlobalCheckpoint == that.leaderGlobalCheckpoint && | ||
| followerGlobalCheckpoint == that.followerGlobalCheckpoint && | ||
| Objects.equals(followerIndex, that.followerIndex); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(followerIndex, shardId, leaderGlobalCheckpoint, followerGlobalCheckpoint); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.