Skip to content
Merged
Show file tree
Hide file tree
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 Dec 22, 2018
f9f530e
Replaced ccr / ilm integ test with multi cluster integ test and
martijnvg Dec 24, 2018
80bb2ef
Fixed tests
martijnvg Dec 24, 2018
a265c2a
Added more tests
martijnvg Dec 24, 2018
e281b03
Rename class to WaitForIndexingCompleteStep
gwbrown Jan 3, 2019
07f0136
Factor "ccr" out into constant
gwbrown Jan 3, 2019
509718c
Add note about leader index to error message
gwbrown Jan 3, 2019
974bb8b
Factor out mocking into methods
gwbrown Jan 3, 2019
97df36b
Merge branch 'master' into pr/36970
gwbrown Jan 4, 2019
37bd0ef
Fix error message in test
gwbrown Jan 4, 2019
94dc951
[WIP] Add rollover-based test case
gwbrown Jan 5, 2019
e996f83
Merge branch 'master' into pr/36970
gwbrown Jan 5, 2019
3949445
Decreased read_poll_timeout from 60 seconds to 1 second.
martijnvg Jan 7, 2019
0ef7002
Adjusted testGetNextActionName() test
martijnvg Jan 7, 2019
6bb4055
Merge branch 'master' into pr/36970
gwbrown Jan 8, 2019
2d368ab
More informative message when following is paused
gwbrown Jan 8, 2019
7485773
Remove index settings from step info
gwbrown Jan 8, 2019
d96ebbb
Javadoc for UnfollowAction
gwbrown Jan 8, 2019
464c256
UnfollowAction hashcode
gwbrown Jan 8, 2019
5d63a5a
Handle deleted indices in WaitForIndexingComplete
gwbrown Jan 8, 2019
f63e73d
added assertion messages
martijnvg Jan 9, 2019
deac47a
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg Jan 9, 2019
886a3f5
Moved pause follower index, close follower index and
martijnvg Jan 9, 2019
2b60e54
Remove unused imports
gwbrown Jan 9, 2019
6d0e236
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg Jan 10, 2019
533bc4f
Allow UnfollowAction in Warm and Cold phases
gwbrown Jan 10, 2019
731d8d2
Add Unfollow action to HLRC
gwbrown Jan 11, 2019
67f970e
added docs for the unfollow action
martijnvg Jan 11, 2019
272b8d6
added wait for yellow step. That will run after open index step,
martijnvg Jan 11, 2019
ea93eda
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg Jan 11, 2019
e9b252e
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg Jan 14, 2019
0416490
docs iter
martijnvg Jan 14, 2019
443fc4a
changed WaitForYellowStep to be a AsyncWaitStep
martijnvg Jan 14, 2019
5abf557
take into account no IndexRoutingTable
martijnvg Jan 14, 2019
caa13ce
Add Unfollow to Warm/Cold phase ordering test
gwbrown Jan 14, 2019
7f521e8
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg Jan 15, 2019
5d3d661
OpenFollowerIndexStep cannot extend from AbstractUnfollowIndexStep,
martijnvg Jan 15, 2019
f7e74d4
Add `indexing_complete` setting to Wait step info
gwbrown Jan 15, 2019
7c1749b
Added Unfollow to the Actions docs ToC
gwbrown Jan 15, 2019
fcf34e6
Switch Info to hardcoded false
gwbrown Jan 15, 2019
c02f8cb
fixed checkstyle violation
martijnvg Jan 16, 2019
a9b2663
Merge remote-tracking branch 'es/master' into ccr_ilm_follower_indices
martijnvg Jan 17, 2019
bb67cdb
Merge branch 'master' into pr/36970
gwbrown Jan 17, 2019
3ee6298
Fix a couple tests
gwbrown Jan 17, 2019
f1c05bd
Run SetPriority before Unfollow
gwbrown Jan 18, 2019
ca0d2cc
Merge branch 'master' into pr/36970
gwbrown Jan 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.elasticsearch.xpack.core.indexlifecycle.RolloverAction;
import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction;
import org.elasticsearch.xpack.core.indexlifecycle.TimeseriesLifecycleType;
import org.elasticsearch.xpack.core.indexlifecycle.UnfollowAction;
import org.elasticsearch.xpack.core.indexlifecycle.action.DeleteLifecycleAction;
import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction;
import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction;
Expand Down Expand Up @@ -425,7 +426,8 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
new NamedWriteableRegistry.Entry(LifecycleAction.class, RolloverAction.NAME, RolloverAction::new),
new NamedWriteableRegistry.Entry(LifecycleAction.class, ShrinkAction.NAME, ShrinkAction::new),
new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new),
new NamedWriteableRegistry.Entry(LifecycleAction.class, FreezeAction.NAME, FreezeAction::new)
new NamedWriteableRegistry.Entry(LifecycleAction.class, FreezeAction.NAME, FreezeAction::new),
new NamedWriteableRegistry.Entry(LifecycleAction.class, UnfollowAction.NAME, UnfollowAction::new)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TimeseriesLifecycleType implements LifecycleType {

public static final String TYPE = "timeseries";
static final List<String> VALID_PHASES = Arrays.asList("hot", "warm", "cold", "delete");
static final List<String> ORDERED_VALID_HOT_ACTIONS = Collections.singletonList(RolloverAction.NAME);
static final List<String> ORDERED_VALID_HOT_ACTIONS = Arrays.asList(UnfollowAction.NAME, RolloverAction.NAME);
static final List<String> ORDERED_VALID_WARM_ACTIONS = Arrays.asList(ReadOnlyAction.NAME, AllocateAction.NAME,
ShrinkAction.NAME, ForceMergeAction.NAME);
static final List<String> ORDERED_VALID_COLD_ACTIONS = Arrays.asList(AllocateAction.NAME, FreezeAction.NAME);
Expand Down
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;
}

@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);
}
}
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) {
PauseFollowAction.Request request = new PauseFollowAction.Request(followerIndex);
getClient().execute(PauseFollowAction.INSTANCE, request, ActionListener.wrap(
r -> {
assert r.isAcknowledged();
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();
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();
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();
listener.onResponse(true);
},
listener::onFailure
));
}

}
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();
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);
}
}
}
}
Loading