|
@@ -13,7 +13,6 @@ import org.apache.logging.log4j.Logger;
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
|
|
|
import org.elasticsearch.cluster.ClusterInfo;
|
|
|
-import org.elasticsearch.cluster.ClusterName;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.ESAllocationTestCase;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
@@ -37,8 +36,11 @@ import org.elasticsearch.snapshots.SnapshotShardSizeInfo;
|
|
|
import java.util.Collections;
|
|
|
|
|
|
import static java.util.Collections.emptyMap;
|
|
|
+import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING;
|
|
|
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
|
|
|
+import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
|
|
|
import static org.elasticsearch.cluster.routing.allocation.RoutingNodesUtils.numberOfShardsOfType;
|
|
|
+import static org.hamcrest.Matchers.empty;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
public class SameShardRoutingTests extends ESAllocationTestCase {
|
|
@@ -48,14 +50,19 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
|
|
|
AllocationService strategy = createAllocationService(
|
|
|
Settings.builder().put(SameShardAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.getKey(), true).build());
|
|
|
|
|
|
+ final Settings.Builder indexSettings = settings(Version.CURRENT);
|
|
|
+ if (randomBoolean()) {
|
|
|
+ indexSettings.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1");
|
|
|
+ }
|
|
|
+
|
|
|
Metadata metadata = Metadata.builder()
|
|
|
- .put(IndexMetadata.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(1))
|
|
|
+ .put(IndexMetadata.builder("test").settings(indexSettings).numberOfShards(2).numberOfReplicas(1))
|
|
|
.build();
|
|
|
|
|
|
RoutingTable routingTable = RoutingTable.builder()
|
|
|
.addAsNew(metadata.index("test"))
|
|
|
.build();
|
|
|
- ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata)
|
|
|
+ ClusterState clusterState = ClusterState.builder(CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metadata(metadata)
|
|
|
.routingTable(routingTable).build();
|
|
|
|
|
|
logger.info("--> adding two nodes with the same host");
|
|
@@ -88,6 +95,54 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testSameHostCheckDisabledByAutoExpandReplicas() {
|
|
|
+ final AllocationService strategy = createAllocationService(
|
|
|
+ Settings.builder().put(SameShardAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.getKey(), true).build());
|
|
|
+
|
|
|
+ final Metadata metadata = Metadata.builder()
|
|
|
+ .put(IndexMetadata.builder("test").settings(settings(Version.CURRENT)
|
|
|
+ .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
|
|
+ .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 99)
|
|
|
+ .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all")))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final DiscoveryNode node1 = new DiscoveryNode(
|
|
|
+ "node1",
|
|
|
+ "node1",
|
|
|
+ "node1",
|
|
|
+ "test1",
|
|
|
+ "test1",
|
|
|
+ buildNewFakeTransportAddress(),
|
|
|
+ emptyMap(),
|
|
|
+ MASTER_DATA_ROLES,
|
|
|
+ Version.CURRENT);
|
|
|
+
|
|
|
+
|
|
|
+ final DiscoveryNode node2 = new DiscoveryNode(
|
|
|
+ "node2",
|
|
|
+ "node2",
|
|
|
+ "node2",
|
|
|
+ "test1",
|
|
|
+ "test1",
|
|
|
+ buildNewFakeTransportAddress(),
|
|
|
+ emptyMap(),
|
|
|
+ MASTER_DATA_ROLES,
|
|
|
+ Version.CURRENT);
|
|
|
+
|
|
|
+ final ClusterState clusterState = applyStartedShardsUntilNoChange(ClusterState
|
|
|
+ .builder(CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
|
|
|
+ .metadata(metadata)
|
|
|
+ .routingTable(RoutingTable.builder()
|
|
|
+ .addAsNew(metadata.index("test"))
|
|
|
+ .build())
|
|
|
+ .nodes(
|
|
|
+ DiscoveryNodes.builder()
|
|
|
+ .add(node1)
|
|
|
+ .add(node2)).build(), strategy);
|
|
|
+
|
|
|
+ assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED), empty());
|
|
|
+ }
|
|
|
+
|
|
|
public void testForceAllocatePrimaryOnSameNodeNotAllowed() {
|
|
|
SameShardAllocationDecider decider = new SameShardAllocationDecider(
|
|
|
Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
|