Search in sources :

Example 6 with ObjectIntHashMap

use of com.carrotsearch.hppc.ObjectIntHashMap in project elasticsearch by elastic.

the class AwarenessAllocationIT method testSimpleAwareness.

public void testSimpleAwareness() throws Exception {
    Settings commonSettings = Settings.builder().put("cluster.routing.allocation.awareness.attributes", "rack_id").build();
    logger.info("--> starting 2 nodes on the same rack");
    internalCluster().startNodes(2, Settings.builder().put(commonSettings).put("node.attr.rack_id", "rack_1").build());
    createIndex("test1");
    createIndex("test2");
    NumShards test1 = getNumShards("test1");
    NumShards test2 = getNumShards("test2");
    //no replicas will be allocated as both indices end up on a single node
    final int totalPrimaries = test1.numPrimaries + test2.numPrimaries;
    ensureGreen();
    logger.info("--> starting 1 node on a different rack");
    final String node3 = internalCluster().startNode(Settings.builder().put(commonSettings).put("node.attr.rack_id", "rack_2").build());
    // On slow machines the initial relocation might be delayed
    assertThat(awaitBusy(() -> {
        logger.info("--> waiting for no relocation");
        ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("3").setWaitForNoRelocatingShards(true).get();
        if (clusterHealth.isTimedOut()) {
            return false;
        }
        logger.info("--> checking current state");
        ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
        // verify that we have all the primaries on node3
        ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();
        for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
            for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
                for (ShardRouting shardRouting : indexShardRoutingTable) {
                    counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
                }
            }
        }
        return counts.get(node3) == totalPrimaries;
    }, 10, TimeUnit.SECONDS), equalTo(true));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ObjectIntHashMap(com.carrotsearch.hppc.ObjectIntHashMap) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Settings(org.elasticsearch.common.settings.Settings)

Example 7 with ObjectIntHashMap

use of com.carrotsearch.hppc.ObjectIntHashMap in project elasticsearch by elastic.

the class AwarenessAllocationIT method testAwarenessZonesIncrementalNodes.

public void testAwarenessZonesIncrementalNodes() throws Exception {
    Settings commonSettings = Settings.builder().put("cluster.routing.allocation.awareness.force.zone.values", "a,b").put("cluster.routing.allocation.awareness.attributes", "zone").build();
    logger.info("--> starting 2 nodes on zones 'a' & 'b'");
    List<String> nodes = internalCluster().startNodes(Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(), Settings.builder().put(commonSettings).put("node.attr.zone", "b").build());
    String A_0 = nodes.get(0);
    String B_0 = nodes.get(1);
    client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 5).put("index.number_of_replicas", 1)).execute().actionGet();
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").setWaitForNoRelocatingShards(true).execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
            }
        }
    }
    assertThat(counts.get(A_0), equalTo(5));
    assertThat(counts.get(B_0), equalTo(5));
    logger.info("--> starting another node in zone 'b'");
    String B_1 = internalCluster().startNode(Settings.builder().put(commonSettings).put("node.attr.zone", "b").build());
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("3").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    client().admin().cluster().prepareReroute().get();
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("3").setWaitForActiveShards(10).setWaitForNoRelocatingShards(true).execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    counts = new ObjectIntHashMap<>();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
            }
        }
    }
    assertThat(counts.get(A_0), equalTo(5));
    assertThat(counts.get(B_0), equalTo(3));
    assertThat(counts.get(B_1), equalTo(2));
    String noZoneNode = internalCluster().startNode();
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("4").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    client().admin().cluster().prepareReroute().get();
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("4").setWaitForActiveShards(10).setWaitForNoRelocatingShards(true).execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    counts = new ObjectIntHashMap<>();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
            }
        }
    }
    assertThat(counts.get(A_0), equalTo(5));
    assertThat(counts.get(B_0), equalTo(3));
    assertThat(counts.get(B_1), equalTo(2));
    assertThat(counts.containsKey(noZoneNode), equalTo(false));
    client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put("cluster.routing.allocation.awareness.attributes", "").build()).get();
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("4").setWaitForActiveShards(10).setWaitForNoRelocatingShards(true).execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    counts = new ObjectIntHashMap<>();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                counts.addTo(clusterState.nodes().get(shardRouting.currentNodeId()).getName(), 1);
            }
        }
    }
    assertThat(counts.get(A_0), equalTo(3));
    assertThat(counts.get(B_0), equalTo(3));
    assertThat(counts.get(B_1), equalTo(2));
    assertThat(counts.get(noZoneNode), equalTo(2));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ObjectIntHashMap(com.carrotsearch.hppc.ObjectIntHashMap) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Settings(org.elasticsearch.common.settings.Settings)

Example 8 with ObjectIntHashMap

use of com.carrotsearch.hppc.ObjectIntHashMap in project TeeTime by teetime-framework.

the class A2InvalidThreadAssignmentCheck method check.

@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public void check() {
    int color = DEFAULT_COLOR;
    ObjectIntMap<AbstractStage> colors = new ObjectIntHashMap<AbstractStage>();
    ThreadPainter threadPainter = new ThreadPainter();
    Traverser traverser = new Traverser(threadPainter);
    for (AbstractStage threadableStage : threadableStages) {
        color++;
        colors.put(threadableStage, color);
        threadPainter.reset(colors, color, threadableStages);
        traverser.traverse(threadableStage);
    }
}
Also used : ObjectIntHashMap(com.carrotsearch.hppc.ObjectIntHashMap) Traverser(teetime.framework.Traverser) AbstractStage(teetime.framework.AbstractStage)

Aggregations

ObjectIntHashMap (com.carrotsearch.hppc.ObjectIntHashMap)8 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)5 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)3 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)3 Settings (org.elasticsearch.common.settings.Settings)3 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)2 Mutation (org.apache.cassandra.db.Mutation)1 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 Replica (org.apache.cassandra.locator.Replica)1 BytesRef (org.apache.lucene.util.BytesRef)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)1 AbstractStage (teetime.framework.AbstractStage)1 Traverser (teetime.framework.Traverser)1