Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -13,7 +13,6 @@
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.ClusterInfo;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ESAllocationTestCase;
Expand Down Expand Up @@ -59,8 +58,6 @@

import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static org.elasticsearch.cluster.ClusterModule.BALANCED_ALLOCATOR;
import static org.elasticsearch.cluster.ClusterModule.DESIRED_BALANCE_ALLOCATOR;
import static org.elasticsearch.cluster.routing.RoutingNodesHelper.shardsWithState;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
Expand All @@ -77,10 +74,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {

public void testMoveShardCommand() {
AllocationService allocation = createAllocationService(
Settings.builder()
.put("cluster.routing.allocation.node_concurrent_recoveries", 10)
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).build()
);

logger.info("creating an index with 1 shard, no replica");
Expand Down Expand Up @@ -144,7 +138,6 @@ public void testAllocateCommand() {
Settings.builder()
.put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")
.put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none")
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
);
final String index = "test";
Expand Down Expand Up @@ -363,7 +356,6 @@ public void testAllocateStalePrimaryCommand() {
Settings.builder()
.put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")
.put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none")
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
);
final String index = "test";
Expand Down Expand Up @@ -427,7 +419,6 @@ public void testCancelCommand() {
Settings.builder()
.put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")
.put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none")
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
);

Expand Down Expand Up @@ -724,32 +715,7 @@ public void testSerialization() throws Exception {
in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);

// Now we can read them!
AllocationCommands sCommands = AllocationCommands.readFrom(in);

assertThat(sCommands.commands().size(), equalTo(5));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(1));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).index(), equalTo("test"));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).node(), equalTo("node1"));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).acceptDataLoss(), equalTo(true));

assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).shardId(), equalTo(2));
assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).index(), equalTo("test"));
assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).node(), equalTo("node1"));
assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).acceptDataLoss(), equalTo(true));

assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).shardId(), equalTo(2));
assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).index(), equalTo("test"));
assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).node(), equalTo("node1"));

assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).shardId(), equalTo(3));
assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).index(), equalTo("test"));
assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).fromNode(), equalTo("node2"));
assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).toNode(), equalTo("node3"));

assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).shardId(), equalTo(4));
assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).index(), equalTo("test"));
assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).node(), equalTo("node5"));
assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).allowPrimary(), equalTo(true));
assertThat(AllocationCommands.readFrom(in), equalTo(commands));
}

public void testXContent() throws Exception {
Expand Down Expand Up @@ -802,32 +768,19 @@ public void testXContent() throws Exception {
// move two tokens, parser expected to be "on" `commands` field
parser.nextToken();
parser.nextToken();
AllocationCommands sCommands = AllocationCommands.fromXContent(parser);

assertThat(sCommands.commands().size(), equalTo(5));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(1));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).index(), equalTo("test"));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).node(), equalTo("node1"));
assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).acceptDataLoss(), equalTo(true));

assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).shardId(), equalTo(2));
assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).index(), equalTo("test"));
assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).node(), equalTo("node1"));
assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).acceptDataLoss(), equalTo(true));

assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).shardId(), equalTo(2));
assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).index(), equalTo("test"));
assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).node(), equalTo("node1"));

assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).shardId(), equalTo(3));
assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).index(), equalTo("test"));
assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).fromNode(), equalTo("node2"));
assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).toNode(), equalTo("node3"));

assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).shardId(), equalTo(4));
assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).index(), equalTo("test"));
assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).node(), equalTo("node5"));
assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).allowPrimary(), equalTo(true));

assertThat(
AllocationCommands.fromXContent(parser),
equalTo(
new AllocationCommands(
new AllocateEmptyPrimaryAllocationCommand("test", 1, "node1", true),
new AllocateStalePrimaryAllocationCommand("test", 2, "node1", true),
new AllocateReplicaAllocationCommand("test", 2, "node1"),
new MoveAllocationCommand("test", 3, "node2", "node3"),
new CancelAllocationCommand("test", 4, "node5", true)
)
)
);
}

@Override
Expand All @@ -837,10 +790,7 @@ protected NamedXContentRegistry xContentRegistry() {

public void testMoveShardToNonDataNode() {
AllocationService allocation = createAllocationService(
Settings.builder()
.put("cluster.routing.allocation.node_concurrent_recoveries", 10)
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).build()
);

logger.info("creating an index with 1 shard, no replica");
Expand Down Expand Up @@ -910,10 +860,7 @@ public void testMoveShardToNonDataNode() {

public void testMoveShardFromNonDataNode() {
AllocationService allocation = createAllocationService(
Settings.builder()
.put("cluster.routing.allocation.node_concurrent_recoveries", 10)
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).build()
);

logger.info("creating an index with 1 shard, no replica");
Expand Down Expand Up @@ -985,7 +932,6 @@ public void testConflictingCommandsInSingleRequest() {
Settings.builder()
.put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none")
.put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none")
.put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), randomShardsAllocator())
.build()
);

Expand Down Expand Up @@ -1091,8 +1037,4 @@ public void testConflictingCommandsInSingleRequest() {
);
}).getMessage(), containsString("all copies of [" + index3 + "][0] are already assigned. Use the move allocation command instead"));
}

private static String randomShardsAllocator() {
return randomFrom(BALANCED_ALLOCATOR, DESIRED_BALANCE_ALLOCATOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
import static org.elasticsearch.common.settings.ClusterSettings.createBuiltInClusterSettings;

public abstract class ESAllocationTestCase extends ESTestCase {
private static final ClusterSettings EMPTY_CLUSTER_SETTINGS = new ClusterSettings(
Settings.EMPTY,
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS
);

public static final SnapshotsInfoService SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES = () -> new SnapshotShardSizeInfo(Map.of()) {
@Override
Expand Down