Search in sources :

Example 16 with Metadata

use of org.elasticsearch.cluster.metadata.Metadata in project elasticsearch by elastic.

the class RoutingIteratorTests method testNodeSelectorRouting.

public void testNodeSelectorRouting() {
    AllocationService strategy = createAllocationService(Settings.builder().put("cluster.routing.allocation.node_concurrent_recoveries", 10).put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), "always").build());
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).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).routingTable(routingTable).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("fred", "node1", singletonMap("disk", "ebs"))).add(newNode("barney", "node2", singletonMap("disk", "ephemeral"))).localNodeId("node1")).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    ShardsIterator shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("disk:ebs", clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node1"));
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("dis*:eph*", clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node2"));
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("fred", clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node1"));
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("bar*", clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node2"));
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt(new String[] { "disk:eph*", "disk:ebs" }, clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(2));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node2"));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node1"));
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt(new String[] { "disk:*", "invalid_name" }, clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(2));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node2"));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node1"));
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt(new String[] { "disk:*", "disk:*" }, clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(2));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node2"));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node1"));
    try {
        shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("welma", clusterState.nodes());
        fail("should have raised illegalArgumentException");
    } catch (IllegalArgumentException illegal) {
    //expected exception
    }
    shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("fred", clusterState.nodes());
    assertThat(shardsIterator.size(), equalTo(1));
    assertThat(shardsIterator.nextOrNull().currentNodeId(), equalTo("node1"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) ShardsIterator(org.elasticsearch.cluster.routing.ShardsIterator) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 17 with Metadata

use of org.elasticsearch.cluster.metadata.Metadata in project elasticsearch by elastic.

the class RoutingIteratorTests method testRandomRouting.

public void testRandomRouting() {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build();
    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.nextOrNull(), notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting3, notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting1, not(sameInstance(shardRouting2)));
    assertThat(shardRouting1, sameInstance(shardRouting3));
}
Also used : RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) PlainShardIterator(org.elasticsearch.cluster.routing.PlainShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 18 with Metadata

use of org.elasticsearch.cluster.metadata.Metadata in project elasticsearch by elastic.

the class RoutingIteratorTests method testIterator2.

public void testIterator2() {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build();
    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsIt(0);
    assertThat(shardIterator.size(), equalTo(2));
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.remaining(), equalTo(1));
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
    assertThat(shardRouting2, not(sameInstance(shardRouting1)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
    shardIterator = routingTable.index("test1").shard(0).shardsIt(1);
    assertThat(shardIterator.size(), equalTo(2));
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    ShardRouting shardRouting4 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    assertThat(shardRouting2, not(sameInstance(shardRouting1)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting1, not(sameInstance(shardRouting3)));
    assertThat(shardRouting2, not(sameInstance(shardRouting4)));
    assertThat(shardRouting1, sameInstance(shardRouting4));
    assertThat(shardRouting2, sameInstance(shardRouting3));
    shardIterator = routingTable.index("test1").shard(0).shardsIt(2);
    assertThat(shardIterator.size(), equalTo(2));
    ShardRouting shardRouting5 = shardIterator.nextOrNull();
    assertThat(shardRouting5, notNullValue());
    ShardRouting shardRouting6 = shardIterator.nextOrNull();
    assertThat(shardRouting6, notNullValue());
    assertThat(shardRouting6, not(sameInstance(shardRouting5)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting5, sameInstance(shardRouting1));
    assertThat(shardRouting6, sameInstance(shardRouting2));
    shardIterator = routingTable.index("test1").shard(0).shardsIt(3);
    assertThat(shardIterator.size(), equalTo(2));
    ShardRouting shardRouting7 = shardIterator.nextOrNull();
    assertThat(shardRouting7, notNullValue());
    ShardRouting shardRouting8 = shardIterator.nextOrNull();
    assertThat(shardRouting8, notNullValue());
    assertThat(shardRouting8, not(sameInstance(shardRouting7)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting7, sameInstance(shardRouting3));
    assertThat(shardRouting8, sameInstance(shardRouting4));
    shardIterator = routingTable.index("test1").shard(0).shardsIt(4);
    assertThat(shardIterator.size(), equalTo(2));
    ShardRouting shardRouting9 = shardIterator.nextOrNull();
    assertThat(shardRouting9, notNullValue());
    ShardRouting shardRouting10 = shardIterator.nextOrNull();
    assertThat(shardRouting10, notNullValue());
    assertThat(shardRouting10, not(sameInstance(shardRouting9)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting9, sameInstance(shardRouting5));
    assertThat(shardRouting10, sameInstance(shardRouting6));
}
Also used : RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) PlainShardIterator(org.elasticsearch.cluster.routing.PlainShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 19 with Metadata

use of org.elasticsearch.cluster.metadata.Metadata in project elasticsearch by elastic.

the class ZenDiscoveryIT method testHandleNodeJoin_incompatibleClusterState.

public void testHandleNodeJoin_incompatibleClusterState() throws UnknownHostException {
    Settings nodeSettings = Settings.builder().put("discovery.type", // <-- To override the local setting if set externally
    "zen").build();
    String masterOnlyNode = internalCluster().startMasterOnlyNode(nodeSettings);
    String node1 = internalCluster().startNode(nodeSettings);
    ZenDiscovery zenDiscovery = (ZenDiscovery) internalCluster().getInstance(Discovery.class, masterOnlyNode);
    ClusterService clusterService = internalCluster().getInstance(ClusterService.class, node1);
    final ClusterState state = clusterService.state();
    MetaData.Builder mdBuilder = MetaData.builder(state.metaData());
    mdBuilder.putCustom(CustomMetaData.TYPE, new CustomMetaData("data"));
    ClusterState stateWithCustomMetaData = ClusterState.builder(state).metaData(mdBuilder).build();
    final AtomicReference<IllegalStateException> holder = new AtomicReference<>();
    DiscoveryNode node = state.nodes().getLocalNode();
    zenDiscovery.handleJoinRequest(node, stateWithCustomMetaData, new MembershipAction.JoinCallback() {

        @Override
        public void onSuccess() {
        }

        @Override
        public void onFailure(Exception e) {
            holder.set((IllegalStateException) e);
        }
    });
    assertThat(holder.get(), notNullValue());
    assertThat(holder.get().getMessage(), equalTo("failure when sending a validation request to node"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Discovery(org.elasticsearch.discovery.Discovery) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) TransportException(org.elasticsearch.transport.TransportException) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) ClusterService(org.elasticsearch.cluster.service.ClusterService) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Settings(org.elasticsearch.common.settings.Settings)

Example 20 with Metadata

use of org.elasticsearch.cluster.metadata.Metadata in project elasticsearch by elastic.

the class PublishClusterStateActionTests method testFailToPublishWithLessThanMinMasterNodes.

public void testFailToPublishWithLessThanMinMasterNodes() throws Exception {
    final int masterNodes = randomIntBetween(1, 10);
    MockNode master = createMockNode("master");
    DiscoveryNodes.Builder discoveryNodesBuilder = DiscoveryNodes.builder().add(master.discoveryNode);
    for (int i = 1; i < masterNodes; i++) {
        discoveryNodesBuilder.add(createMockNode("node" + i).discoveryNode);
    }
    final int dataNodes = randomIntBetween(0, 5);
    final Settings dataSettings = Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build();
    for (int i = 0; i < dataNodes; i++) {
        discoveryNodesBuilder.add(createMockNode("data_" + i, dataSettings, null).discoveryNode);
    }
    discoveryNodesBuilder.localNodeId(master.discoveryNode.getId()).masterNodeId(master.discoveryNode.getId());
    DiscoveryNodes discoveryNodes = discoveryNodesBuilder.build();
    MetaData metaData = MetaData.EMPTY_META_DATA;
    ClusterState clusterState = ClusterState.builder(CLUSTER_NAME).metaData(metaData).nodes(discoveryNodes).build();
    ClusterState previousState = master.clusterState;
    try {
        publishState(master.action, clusterState, previousState, masterNodes + randomIntBetween(1, 5));
        fail("cluster state publishing didn't fail despite of not having enough nodes");
    } catch (Discovery.FailedToCommitClusterStateException expected) {
        logger.debug("failed to publish as expected", expected);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Discovery(org.elasticsearch.discovery.Discovery) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Settings(org.elasticsearch.common.settings.Settings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

MetaData (org.elasticsearch.cluster.metadata.MetaData)244 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)223 ClusterState (org.elasticsearch.cluster.ClusterState)179 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)138 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)52 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)48 Settings (org.elasticsearch.common.settings.Settings)43 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)32 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)30 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)27 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)26 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)26 Index (org.elasticsearch.index.Index)25 Matchers.containsString (org.hamcrest.Matchers.containsString)23 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)21 HashMap (java.util.HashMap)19 HashSet (java.util.HashSet)18 ShardId (org.elasticsearch.index.shard.ShardId)17 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)17 ArrayList (java.util.ArrayList)15