use of org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider in project OpenSearch by opensearch-project.
the class ClusterModule method createAllocationDeciders.
// TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
/**
* Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins.
*/
public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings, List<ClusterPlugin> clusterPlugins) {
// collect deciders by class so that we can detect duplicates
Map<Class, AllocationDecider> deciders = new LinkedHashMap<>();
addAllocationDecider(deciders, new MaxRetryAllocationDecider());
addAllocationDecider(deciders, new ResizeAllocationDecider());
addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider());
addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider());
addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ConcurrentRecoveriesAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new NodeVersionAllocationDecider());
addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider());
addAllocationDecider(deciders, new RestoreInProgressAllocationDecider());
addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new NodeLoadAwareAllocationDecider(settings, clusterSettings));
clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));
return deciders.values();
}
use of org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider in project OpenSearch by opensearch-project.
the class ResizeAllocationDeciderTests method testNonResizeRouting.
public void testNonResizeRouting() {
ClusterState clusterState = createInitialClusterState(true);
ResizeAllocationDecider resizeAllocationDecider = new ResizeAllocationDecider();
RoutingAllocation routingAllocation = new RoutingAllocation(null, null, clusterState, null, null, 0);
ShardRouting shardRouting = TestShardRouting.newShardRouting("non-resize", 0, null, true, ShardRoutingState.UNASSIGNED);
assertEquals(Decision.ALWAYS, resizeAllocationDecider.canAllocate(shardRouting, routingAllocation));
assertEquals(Decision.ALWAYS, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation));
}
use of org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider in project OpenSearch by opensearch-project.
the class ResizeAllocationDeciderTests method testSourceNotActive.
public void testSourceNotActive() {
ClusterState clusterState = createInitialClusterState(false);
Metadata.Builder metaBuilder = Metadata.builder(clusterState.metadata());
metaBuilder.put(IndexMetadata.builder("target").settings(settings(Version.CURRENT).put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME.getKey(), "source").put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID_KEY, IndexMetadata.INDEX_UUID_NA_VALUE)).numberOfShards(4).numberOfReplicas(0));
Metadata metadata = metaBuilder.build();
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(clusterState.routingTable());
routingTableBuilder.addAsNew(metadata.index("target"));
clusterState = ClusterState.builder(clusterState).routingTable(routingTableBuilder.build()).metadata(metadata).build();
Index idx = clusterState.metadata().index("target").getIndex();
ResizeAllocationDecider resizeAllocationDecider = new ResizeAllocationDecider();
RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, null, null, 0);
int shardId = randomIntBetween(0, 3);
int sourceShardId = IndexMetadata.selectSplitShard(shardId, clusterState.metadata().index("source"), 4).id();
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(idx, shardId), null, true, ShardRoutingState.UNASSIGNED, RecoverySource.LocalShardsRecoverySource.INSTANCE);
assertEquals(Decision.NO, resizeAllocationDecider.canAllocate(shardRouting, routingAllocation));
assertEquals(Decision.NO, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation));
assertEquals(Decision.NO, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node2"), routingAllocation));
routingAllocation.debugDecision(true);
assertEquals("source primary shard [[source][" + sourceShardId + "]] is not active", resizeAllocationDecider.canAllocate(shardRouting, routingAllocation).getExplanation());
assertEquals("source primary shard [[source][" + sourceShardId + "]] is not active", resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node0"), routingAllocation).getExplanation());
assertEquals("source primary shard [[source][" + sourceShardId + "]] is not active", resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation).getExplanation());
}
use of org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider in project OpenSearch by opensearch-project.
the class ResizeAllocationDeciderTests method testShrink.
public void testShrink() {
// we don't handle shrink yet
ClusterState clusterState = createInitialClusterState(true);
Metadata.Builder metaBuilder = Metadata.builder(clusterState.metadata());
metaBuilder.put(IndexMetadata.builder("target").settings(settings(Version.CURRENT).put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME.getKey(), "source").put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID_KEY, IndexMetadata.INDEX_UUID_NA_VALUE)).numberOfShards(1).numberOfReplicas(0));
Metadata metadata = metaBuilder.build();
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(clusterState.routingTable());
routingTableBuilder.addAsNew(metadata.index("target"));
clusterState = ClusterState.builder(clusterState).routingTable(routingTableBuilder.build()).metadata(metadata).build();
Index idx = clusterState.metadata().index("target").getIndex();
ResizeAllocationDecider resizeAllocationDecider = new ResizeAllocationDecider();
RoutingAllocation routingAllocation = new RoutingAllocation(null, null, clusterState, null, null, 0);
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(idx, 0), null, true, ShardRoutingState.UNASSIGNED, RecoverySource.LocalShardsRecoverySource.INSTANCE);
assertEquals(Decision.ALWAYS, resizeAllocationDecider.canAllocate(shardRouting, routingAllocation));
assertEquals(Decision.ALWAYS, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation));
assertEquals(Decision.ALWAYS, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node2"), routingAllocation));
}
use of org.opensearch.cluster.routing.allocation.decider.ResizeAllocationDecider in project OpenSearch by opensearch-project.
the class ResizeAllocationDeciderTests method testSourcePrimaryActive.
public void testSourcePrimaryActive() {
ClusterState clusterState = createInitialClusterState(true);
Metadata.Builder metaBuilder = Metadata.builder(clusterState.metadata());
metaBuilder.put(IndexMetadata.builder("target").settings(settings(Version.CURRENT).put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME.getKey(), "source").put(IndexMetadata.INDEX_RESIZE_SOURCE_UUID_KEY, IndexMetadata.INDEX_UUID_NA_VALUE)).numberOfShards(4).numberOfReplicas(0));
Metadata metadata = metaBuilder.build();
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(clusterState.routingTable());
routingTableBuilder.addAsNew(metadata.index("target"));
clusterState = ClusterState.builder(clusterState).routingTable(routingTableBuilder.build()).metadata(metadata).build();
Index idx = clusterState.metadata().index("target").getIndex();
ResizeAllocationDecider resizeAllocationDecider = new ResizeAllocationDecider();
RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, null, null, 0);
int shardId = randomIntBetween(0, 3);
int sourceShardId = IndexMetadata.selectSplitShard(shardId, clusterState.metadata().index("source"), 4).id();
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(idx, shardId), null, true, ShardRoutingState.UNASSIGNED, RecoverySource.LocalShardsRecoverySource.INSTANCE);
assertEquals(Decision.YES, resizeAllocationDecider.canAllocate(shardRouting, routingAllocation));
String allowedNode = clusterState.getRoutingTable().index("source").shard(sourceShardId).primaryShard().currentNodeId();
if ("node1".equals(allowedNode)) {
assertEquals(Decision.YES, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation));
assertEquals(Decision.NO, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node2"), routingAllocation));
} else {
assertEquals(Decision.NO, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation));
assertEquals(Decision.YES, resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node2"), routingAllocation));
}
routingAllocation.debugDecision(true);
assertEquals("source primary is active", resizeAllocationDecider.canAllocate(shardRouting, routingAllocation).getExplanation());
if ("node1".equals(allowedNode)) {
assertEquals("source primary is allocated on this node", resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation).getExplanation());
assertEquals("source primary is allocated on another node", resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node2"), routingAllocation).getExplanation());
} else {
assertEquals("source primary is allocated on another node", resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node1"), routingAllocation).getExplanation());
assertEquals("source primary is allocated on this node", resizeAllocationDecider.canAllocate(shardRouting, clusterState.getRoutingNodes().node("node2"), routingAllocation).getExplanation());
}
}
Aggregations