Makes brnach compile
Commented out toSteps implem,entations and other bits needed to get the branch to compile
This commit is contained in:
parent
f429fc0b3e
commit
9972710e9e
|
@ -144,62 +144,62 @@ public class AllocateAction implements LifecycleAction {
|
||||||
}).forEach(e -> newSettingsBuilder.put(settingPrefix + e.getKey(), e.getValue()));
|
}).forEach(e -> newSettingsBuilder.put(settingPrefix + e.getKey(), e.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConditionalWaitStep getAllocationCheck(AllocationDeciders allocationDeciders, String phase, String index) {
|
// public static ConditionalWaitStep getAllocationCheck(AllocationDeciders allocationDeciders, String phase, String index) {
|
||||||
return new ConditionalWaitStep("wait_allocation", NAME,
|
// return new ConditionalWaitStep("wait_allocation", NAME,
|
||||||
phase, index, (clusterState) -> {
|
// phase, index, (clusterState) -> {
|
||||||
// We only want to make progress if all shards are active so check that first
|
// // We only want to make progress if all shards are active so check that first
|
||||||
if (ActiveShardCount.ALL.enoughShardsActive(clusterState, index) == false) {
|
// if (ActiveShardCount.ALL.enoughShardsActive(clusterState, index) == false) {
|
||||||
logger.debug("[{}] lifecycle action for index [{}] cannot make progress because not all shards are active", NAME,
|
// logger.debug("[{}] lifecycle action for index [{}] cannot make progress because not all shards are active", NAME,
|
||||||
index);
|
// index);
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// All the allocation attributes are already set so just need to
|
// // All the allocation attributes are already set so just need to
|
||||||
// check if the allocation has happened
|
// // check if the allocation has happened
|
||||||
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState.getRoutingNodes(), clusterState, null,
|
// RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState.getRoutingNodes(), clusterState, null,
|
||||||
System.nanoTime());
|
// System.nanoTime());
|
||||||
int allocationPendingShards = 0;
|
// int allocationPendingShards = 0;
|
||||||
List<ShardRouting> allShards = clusterState.getRoutingTable().allShards(index);
|
// List<ShardRouting> allShards = clusterState.getRoutingTable().allShards(index);
|
||||||
for (ShardRouting shardRouting : allShards) {
|
// for (ShardRouting shardRouting : allShards) {
|
||||||
assert shardRouting.active() : "Shard not active, found " + shardRouting.state() + "for shard with id: "
|
// assert shardRouting.active() : "Shard not active, found " + shardRouting.state() + "for shard with id: "
|
||||||
+ shardRouting.shardId();
|
// + shardRouting.shardId();
|
||||||
String currentNodeId = shardRouting.currentNodeId();
|
// String currentNodeId = shardRouting.currentNodeId();
|
||||||
boolean canRemainOnCurrentNode = allocationDeciders.canRemain(shardRouting,
|
// boolean canRemainOnCurrentNode = allocationDeciders.canRemain(shardRouting,
|
||||||
clusterState.getRoutingNodes().node(currentNodeId), allocation).type() == Decision.Type.YES;
|
// clusterState.getRoutingNodes().node(currentNodeId), allocation).type() == Decision.Type.YES;
|
||||||
if (canRemainOnCurrentNode == false) {
|
// if (canRemainOnCurrentNode == false) {
|
||||||
allocationPendingShards++;
|
// allocationPendingShards++;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (allocationPendingShards > 0) {
|
// if (allocationPendingShards > 0) {
|
||||||
logger.debug("[{}] lifecycle action for index [{}] waiting for [{}] shards "
|
// logger.debug("[{}] lifecycle action for index [{}] waiting for [{}] shards "
|
||||||
+ "to be allocated to nodes matching the given filters", NAME, index, allocationPendingShards);
|
// + "to be allocated to nodes matching the given filters", NAME, index, allocationPendingShards);
|
||||||
return false;
|
// return false;
|
||||||
} else {
|
// } else {
|
||||||
logger.debug("[{}] lifecycle action for index [{}] complete", NAME, index);
|
// logger.debug("[{}] lifecycle action for index [{}] complete", NAME, index);
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
ClusterStateUpdateStep updateAllocationSettings = new ClusterStateUpdateStep(
|
// ClusterStateUpdateStep updateAllocationSettings = new ClusterStateUpdateStep(
|
||||||
"update_allocation", NAME, phase, index.getName(), (clusterState) -> {
|
// "update_allocation", NAME, phase, index.getName(), (clusterState) -> {
|
||||||
IndexMetaData idxMeta = clusterState.metaData().index(index);
|
// IndexMetaData idxMeta = clusterState.metaData().index(index);
|
||||||
if (idxMeta == null) {
|
// if (idxMeta == null) {
|
||||||
return clusterState;
|
// return clusterState;
|
||||||
}
|
// }
|
||||||
Settings existingSettings = idxMeta.getSettings();
|
// Settings existingSettings = idxMeta.getSettings();
|
||||||
Settings.Builder newSettings = Settings.builder();
|
// Settings.Builder newSettings = Settings.builder();
|
||||||
addMissingAttrs(include, IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey(), existingSettings, newSettings);
|
// addMissingAttrs(include, IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey(), existingSettings, newSettings);
|
||||||
addMissingAttrs(exclude, IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey(), existingSettings, newSettings);
|
// addMissingAttrs(exclude, IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getKey(), existingSettings, newSettings);
|
||||||
addMissingAttrs(require, IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey(), existingSettings, newSettings);
|
// addMissingAttrs(require, IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey(), existingSettings, newSettings);
|
||||||
return ClusterState.builder(clusterState)
|
// return ClusterState.builder(clusterState)
|
||||||
.metaData(MetaData.builder(clusterState.metaData())
|
// .metaData(MetaData.builder(clusterState.metaData())
|
||||||
.updateSettings(newSettings.build(), index.getName())).build();
|
// .updateSettings(newSettings.build(), index.getName())).build();
|
||||||
});
|
// });
|
||||||
|
|
||||||
return Arrays.asList(updateAllocationSettings, getAllocationCheck(allocationDeciders, phase, index.getName()));
|
return Arrays.asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.LongSupplier;
|
import java.util.function.LongSupplier;
|
||||||
|
@ -67,11 +68,12 @@ public class DeleteAction implements LifecycleAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
String indexName = index.getName();
|
// String indexName = index.getName();
|
||||||
return Collections.singletonList(new ClientStep<DeleteIndexRequestBuilder, DeleteIndexResponse>( "delete",
|
// return Collections.singletonList(new ClientStep<DeleteIndexRequestBuilder, DeleteIndexResponse>( "delete",
|
||||||
NAME, phase, indexName, client.admin().indices().prepareDelete(indexName),
|
// NAME, phase, indexName, client.admin().indices().prepareDelete(indexName),
|
||||||
clusterState -> clusterState.metaData().hasIndex(indexName), response -> true));
|
// clusterState -> clusterState.metaData().hasIndex(indexName), response -> true));
|
||||||
|
return Arrays.asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -97,36 +97,36 @@ public class ForceMergeAction implements LifecycleAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
ClusterStateUpdateStep readOnlyStep = new ClusterStateUpdateStep(
|
// ClusterStateUpdateStep readOnlyStep = new ClusterStateUpdateStep(
|
||||||
"read_only", NAME, phase, index.getName(), (currentState) -> {
|
// "read_only", NAME, phase, index.getName(), (currentState) -> {
|
||||||
Settings readOnlySettings = Settings.builder().put(IndexMetaData.SETTING_BLOCKS_WRITE, true).build();
|
// Settings readOnlySettings = Settings.builder().put(IndexMetaData.SETTING_BLOCKS_WRITE, true).build();
|
||||||
return ClusterState.builder(currentState).metaData(MetaData.builder(currentState.metaData())
|
// return ClusterState.builder(currentState).metaData(MetaData.builder(currentState.metaData())
|
||||||
.updateSettings(readOnlySettings, index.getName())).build();
|
// .updateSettings(readOnlySettings, index.getName())).build();
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
|
// ClientStep<IndicesSegmentsRequestBuilder, IndicesSegmentResponse> segmentCount = new ClientStep<>( "segment_count",
|
||||||
|
// NAME, phase, index.getName(),
|
||||||
|
// client.admin().indices().prepareSegments(index.getName()),
|
||||||
|
// currentState -> false, response -> {
|
||||||
|
// // check if has too many segments
|
||||||
|
// return StreamSupport.stream(response.getIndices().get(index.getName()).spliterator(), false)
|
||||||
|
// .anyMatch(iss -> Arrays.stream(iss.getShards()).anyMatch(p -> p.getSegments().size() > maxNumSegments));
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// ClientStep forceMerge = new ClientStep<ForceMergeRequestBuilder, ForceMergeResponse>( "force_merge",
|
||||||
|
// NAME, phase, index.getName(),
|
||||||
|
// client.admin().indices().prepareForceMerge(index.getName()).setMaxNumSegments(maxNumSegments),
|
||||||
|
// currentState -> false, response -> RestStatus.OK.equals(response.getStatus()));
|
||||||
|
//
|
||||||
|
// ClusterStateUpdateStep readWriteStep = new ClusterStateUpdateStep(
|
||||||
|
// "read_only", NAME, phase, index.getName(), (currentState) -> {
|
||||||
|
// Settings readOnlySettings = Settings.builder().put(IndexMetaData.SETTING_BLOCKS_WRITE, false).build();
|
||||||
|
// return ClusterState.builder(currentState).metaData(MetaData.builder(currentState.metaData())
|
||||||
|
// .updateSettings(readOnlySettings, index.getName())).build();
|
||||||
|
// });
|
||||||
|
|
||||||
ClientStep<IndicesSegmentsRequestBuilder, IndicesSegmentResponse> segmentCount = new ClientStep<>( "segment_count",
|
return Arrays.asList();
|
||||||
NAME, phase, index.getName(),
|
|
||||||
client.admin().indices().prepareSegments(index.getName()),
|
|
||||||
currentState -> false, response -> {
|
|
||||||
// check if has too many segments
|
|
||||||
return StreamSupport.stream(response.getIndices().get(index.getName()).spliterator(), false)
|
|
||||||
.anyMatch(iss -> Arrays.stream(iss.getShards()).anyMatch(p -> p.getSegments().size() > maxNumSegments));
|
|
||||||
});
|
|
||||||
|
|
||||||
ClientStep forceMerge = new ClientStep<ForceMergeRequestBuilder, ForceMergeResponse>( "force_merge",
|
|
||||||
NAME, phase, index.getName(),
|
|
||||||
client.admin().indices().prepareForceMerge(index.getName()).setMaxNumSegments(maxNumSegments),
|
|
||||||
currentState -> false, response -> RestStatus.OK.equals(response.getStatus()));
|
|
||||||
|
|
||||||
ClusterStateUpdateStep readWriteStep = new ClusterStateUpdateStep(
|
|
||||||
"read_only", NAME, phase, index.getName(), (currentState) -> {
|
|
||||||
Settings readOnlySettings = Settings.builder().put(IndexMetaData.SETTING_BLOCKS_WRITE, false).build();
|
|
||||||
return ClusterState.builder(currentState).metaData(MetaData.builder(currentState.metaData())
|
|
||||||
.updateSettings(readOnlySettings, index.getName())).build();
|
|
||||||
});
|
|
||||||
|
|
||||||
return Arrays.asList(readOnlyStep, segmentCount, forceMerge, readWriteStep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -83,14 +83,14 @@ public class ReplicasAction implements LifecycleAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
ClusterStateUpdateStep updateAllocationSettings = new ClusterStateUpdateStep(
|
// ClusterStateUpdateStep updateAllocationSettings = new ClusterStateUpdateStep(
|
||||||
"update_replica_count", NAME, phase, index.getName(), (currentState) ->
|
// "update_replica_count", NAME, phase, index.getName(), (currentState) ->
|
||||||
ClusterState.builder(currentState).metaData(MetaData.builder(currentState.metaData())
|
// ClusterState.builder(currentState).metaData(MetaData.builder(currentState.metaData())
|
||||||
.updateNumberOfReplicas(numberOfReplicas, index.getName())).build());
|
// .updateNumberOfReplicas(numberOfReplicas, index.getName())).build());
|
||||||
ConditionalWaitStep isReplicatedCheck = new ConditionalWaitStep("wait_replicas_allocated", NAME,
|
// ConditionalWaitStep isReplicatedCheck = new ConditionalWaitStep("wait_replicas_allocated", NAME,
|
||||||
phase, index.getName(), (currentState) -> ActiveShardCount.ALL.enoughShardsActive(currentState, index.getName()) );
|
// phase, index.getName(), (currentState) -> ActiveShardCount.ALL.enoughShardsActive(currentState, index.getName()) );
|
||||||
return Arrays.asList(updateAllocationSettings, isReplicatedCheck);
|
return Arrays.asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfReplicas() {
|
public int getNumberOfReplicas() {
|
||||||
|
|
|
@ -6,11 +6,6 @@
|
||||||
package org.elasticsearch.xpack.core.indexlifecycle;
|
package org.elasticsearch.xpack.core.indexlifecycle;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.elasticsearch.action.ActionListener;
|
|
||||||
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
|
||||||
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -22,14 +17,11 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.Index;
|
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.LongSupplier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link LifecycleAction} which deletes the index.
|
* A {@link LifecycleAction} which deletes the index.
|
||||||
|
@ -153,7 +145,7 @@ public class RolloverAction implements LifecycleAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
// ConditionalWaitStep wait = new ConditionalWaitStep(clusterService, "wait_for_rollover", index.getName(), phase, action, (clusterState) -> {
|
// ConditionalWaitStep wait = new ConditionalWaitStep(clusterService, "wait_for_rollover", index.getName(), phase, action, (clusterState) -> {
|
||||||
// // TODO(talevy): actually, needs to RolloverRequest with dryrun to get the appropriate data; clusterState is not enough...
|
// // TODO(talevy): actually, needs to RolloverRequest with dryrun to get the appropriate data; clusterState is not enough...
|
||||||
|
|
|
@ -104,24 +104,24 @@ public class ShrinkAction implements LifecycleAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
String shrunkenIndexName = SHRUNK_INDEX_NAME_PREFIX + index.getName();
|
// String shrunkenIndexName = SHRUNK_INDEX_NAME_PREFIX + index.getName();
|
||||||
// TODO(talevy): magical node.name to allocate to
|
// // TODO(talevy): magical node.name to allocate to
|
||||||
String nodeName = "MAGIC";
|
// String nodeName = "MAGIC";
|
||||||
ClusterStateUpdateStep updateAllocationToOneNode = new ClusterStateUpdateStep(
|
// ClusterStateUpdateStep updateAllocationToOneNode = new ClusterStateUpdateStep(
|
||||||
"move_to_single_node", NAME, phase, index.getName(), (clusterState) -> {
|
// "move_to_single_node", NAME, phase, index.getName(), (clusterState) -> {
|
||||||
IndexMetaData idxMeta = clusterState.metaData().index(index);
|
// IndexMetaData idxMeta = clusterState.metaData().index(index);
|
||||||
if (idxMeta == null) {
|
// if (idxMeta == null) {
|
||||||
return clusterState;
|
// return clusterState;
|
||||||
}
|
// }
|
||||||
Settings.Builder newSettings = Settings.builder()
|
// Settings.Builder newSettings = Settings.builder()
|
||||||
.put(IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_PREFIX, "")
|
// .put(IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_PREFIX, "")
|
||||||
.put(IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX, "")
|
// .put(IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX, "")
|
||||||
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", nodeName);
|
// .put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", nodeName);
|
||||||
return ClusterState.builder(clusterState)
|
// return ClusterState.builder(clusterState)
|
||||||
.metaData(MetaData.builder(clusterState.metaData())
|
// .metaData(MetaData.builder(clusterState.metaData())
|
||||||
.updateSettings(newSettings.build(), index.getName())).build();
|
// .updateSettings(newSettings.build(), index.getName())).build();
|
||||||
});
|
// });
|
||||||
|
|
||||||
// resizeRequest.getTargetIndexRequest().settings(Settings.builder()
|
// resizeRequest.getTargetIndexRequest().settings(Settings.builder()
|
||||||
// .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards)
|
// .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards)
|
||||||
|
@ -132,42 +132,42 @@ public class ShrinkAction implements LifecycleAction {
|
||||||
// resizeRequest.getTargetIndexRequest().alias(new Alias(aliasMetaDataObjectCursor.value.alias()));
|
// resizeRequest.getTargetIndexRequest().alias(new Alias(aliasMetaDataObjectCursor.value.alias()));
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// TODO(talevy): needs access to original index metadata, not just Index
|
// // TODO(talevy): needs access to original index metadata, not just Index
|
||||||
int numReplicas = -1;
|
// int numReplicas = -1;
|
||||||
long lifecycleDate = -1L;
|
// long lifecycleDate = -1L;
|
||||||
Settings targetIndexSettings = Settings.builder()
|
// Settings targetIndexSettings = Settings.builder()
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards)
|
// .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards)
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numReplicas)
|
// .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numReplicas)
|
||||||
.put(LifecycleSettings.LIFECYCLE_INDEX_CREATION_DATE, lifecycleDate)
|
// .put(LifecycleSettings.LIFECYCLE_INDEX_CREATION_DATE, lifecycleDate)
|
||||||
.build();
|
// .build();
|
||||||
CreateIndexRequest targetIndexRequest = new CreateIndexRequest(shrunkenIndexName, targetIndexSettings);
|
// CreateIndexRequest targetIndexRequest = new CreateIndexRequest(shrunkenIndexName, targetIndexSettings);
|
||||||
// TODO(talevy): need access to indexmetadata
|
// TODO(talevy): need access to indexmetadata
|
||||||
// indexMetaData.getAliases().values().spliterator().forEachRemaining(aliasMetaDataObjectCursor -> {
|
// indexMetaData.getAliases().values().spliterator().forEachRemaining(aliasMetaDataObjectCursor -> {
|
||||||
// resizeRequest.getTargetIndexRequest().alias(new Alias(aliasMetaDataObjectCursor.value.alias()));
|
// resizeRequest.getTargetIndexRequest().alias(new Alias(aliasMetaDataObjectCursor.value.alias()));
|
||||||
// });
|
// });
|
||||||
|
|
||||||
ClientStep<ResizeRequestBuilder, ResizeResponse> shrinkStep = new ClientStep<>( "segment_count",
|
// ClientStep<ResizeRequestBuilder, ResizeResponse> shrinkStep = new ClientStep<>( "segment_count",
|
||||||
NAME, phase, index.getName(),
|
// NAME, phase, index.getName(),
|
||||||
|
//
|
||||||
client.admin().indices().prepareResizeIndex(index.getName(), shrunkenIndexName).setTargetIndex(targetIndexRequest),
|
// client.admin().indices().prepareResizeIndex(index.getName(), shrunkenIndexName).setTargetIndex(targetIndexRequest),
|
||||||
currentState -> {
|
// currentState -> {
|
||||||
// check that shrunken index was already created, if so, no need to both client
|
// // check that shrunken index was already created, if so, no need to both client
|
||||||
IndexMetaData shrunkMetaData = currentState.metaData().index(shrunkenIndexName);
|
// IndexMetaData shrunkMetaData = currentState.metaData().index(shrunkenIndexName);
|
||||||
return shrunkMetaData != null && shrunkenIndexName.equals(IndexMetaData.INDEX_SHRINK_SOURCE_NAME
|
// return shrunkMetaData != null && shrunkenIndexName.equals(IndexMetaData.INDEX_SHRINK_SOURCE_NAME
|
||||||
.get(shrunkMetaData.getSettings()));
|
// .get(shrunkMetaData.getSettings()));
|
||||||
|
//
|
||||||
}, ResizeResponse::isAcknowledged);
|
// }, ResizeResponse::isAcknowledged);
|
||||||
|
//
|
||||||
|
//
|
||||||
ConditionalWaitStep shrunkenIndexIsAllocated = new ConditionalWaitStep("wait_replicas_allocated", NAME,
|
// ConditionalWaitStep shrunkenIndexIsAllocated = new ConditionalWaitStep("wait_replicas_allocated", NAME,
|
||||||
phase, index.getName(), (currentState) -> ActiveShardCount.ALL.enoughShardsActive(currentState, index.getName()) );
|
// phase, index.getName(), (currentState) -> ActiveShardCount.ALL.enoughShardsActive(currentState, index.getName()) );
|
||||||
|
//
|
||||||
ClusterStateUpdateStep deleteAndUpdateAliases = new ClusterStateUpdateStep(
|
// ClusterStateUpdateStep deleteAndUpdateAliases = new ClusterStateUpdateStep(
|
||||||
"delete_this_index_set_aliases_on_shrunken", NAME, phase, index.getName(), (clusterState) -> {
|
// "delete_this_index_set_aliases_on_shrunken", NAME, phase, index.getName(), (clusterState) -> {
|
||||||
IndexMetaData idxMeta = clusterState.metaData().index(index);
|
// IndexMetaData idxMeta = clusterState.metaData().index(index);
|
||||||
if (idxMeta == null) {
|
// if (idxMeta == null) {
|
||||||
return clusterState;
|
// return clusterState;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// TODO(talevy): expose - MetadataDeleteIndexService.deleteIndices(clusterState, Set.of(index.getName()))
|
// TODO(talevy): expose - MetadataDeleteIndexService.deleteIndices(clusterState, Set.of(index.getName()))
|
||||||
// also, looks like deletes are special CS tasks
|
// also, looks like deletes are special CS tasks
|
||||||
|
@ -176,12 +176,10 @@ public class ShrinkAction implements LifecycleAction {
|
||||||
// 1. delete index
|
// 1. delete index
|
||||||
// 2. assign alias to shrunken index
|
// 2. assign alias to shrunken index
|
||||||
// 3. assign index.lifecycle settings to shrunken index
|
// 3. assign index.lifecycle settings to shrunken index
|
||||||
return clusterState;
|
// return clusterState;
|
||||||
});
|
// });
|
||||||
|
|
||||||
return Arrays.asList(updateAllocationToOneNode,
|
return Arrays.asList();
|
||||||
AllocateAction.getAllocationCheck(allocationDeciders, phase, index.getName()),
|
|
||||||
shrinkStep, shrunkenIndexIsAllocated, deleteAndUpdateAliases);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
package org.elasticsearch.xpack.core.indexlifecycle;
|
package org.elasticsearch.xpack.core.indexlifecycle;
|
||||||
|
|
||||||
import org.apache.lucene.util.SetOnce;
|
import org.apache.lucene.util.SetOnce;
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -15,15 +13,12 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.Index;
|
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.function.LongSupplier;
|
|
||||||
|
|
||||||
public class MockAction implements LifecycleAction {
|
public class MockAction implements LifecycleAction {
|
||||||
public static final ParseField COMPLETED_FIELD = new ParseField("completed");
|
public static final ParseField COMPLETED_FIELD = new ParseField("completed");
|
||||||
|
@ -89,7 +84,7 @@ public class MockAction implements LifecycleAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Step> toSteps(String phase, Index index, Client client, ThreadPool threadPool, LongSupplier nowSupplier) {
|
public List<Step> toSteps(String phase) {
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,12 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.core.indexlifecycle;
|
package org.elasticsearch.xpack.core.indexlifecycle;
|
||||||
|
|
||||||
import org.elasticsearch.common.Nullable;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy.NextActionProvider;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class TestLifecycleType implements LifecycleType {
|
public class TestLifecycleType implements LifecycleType {
|
||||||
public static final TestLifecycleType INSTANCE = new TestLifecycleType();
|
public static final TestLifecycleType INSTANCE = new TestLifecycleType();
|
||||||
|
@ -41,31 +39,41 @@ public class TestLifecycleType implements LifecycleType {
|
||||||
// return a -> Optional.ofNullable(phase.getActions().entrySet().iterator().next()).map(Map.Entry::getValue).orElse(null);
|
// return a -> Optional.ofNullable(phase.getActions().entrySet().iterator().next()).map(Map.Entry::getValue).orElse(null);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public Phase getFirstPhase(Map<String, Phase> phases) {
|
// public Phase getFirstPhase(Map<String, Phase> phases) {
|
||||||
return phases.values().iterator().next();
|
// return phases.values().iterator().next();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Phase nextPhase(Map<String, Phase> phases, @Nullable Phase currentPhase) {
|
// public Phase nextPhase(Map<String, Phase> phases, @Nullable Phase currentPhase) {
|
||||||
if (currentPhase == null) {
|
// if (currentPhase == null) {
|
||||||
return getFirstPhase(phases);
|
// return getFirstPhase(phases);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
boolean foundPhase = false;
|
// boolean foundPhase = false;
|
||||||
for (Phase phase : phases.values()) {
|
// for (Phase phase : phases.values()) {
|
||||||
if (foundPhase) {
|
// if (foundPhase) {
|
||||||
return phase;
|
// return phase;
|
||||||
} else if (phase.equals(currentPhase)) {
|
// } else if (phase.equals(currentPhase)) {
|
||||||
foundPhase = true;
|
// foundPhase = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(Collection<Phase> phases) {
|
public void validate(Collection<Phase> phases) {
|
||||||
// always valid
|
// always valid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Phase> getOrderedPhases(Map<String, Phase> phases) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<LifecycleAction> getOrderedActions(Phase phase) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue