Package org.elasticsearch.cluster.routing

Examples of org.elasticsearch.cluster.routing.IndexShardRoutingTable


        }


        if (!shardRouting.primary()) {
            // recovery from primary
            IndexShardRoutingTable shardRoutingTable = routingTable.index(shardRouting.index()).shard(shardRouting.id());
            for (ShardRouting entry : shardRoutingTable) {
                if (entry.primary() && entry.started()) {
                    // only recover from started primary, if we can't find one, we will do it next round
                    final DiscoveryNode sourceNode = nodes.get(entry.currentNodeId());
                    try {
View Full Code Here


                        shards.remove(i);
                    } else {
                        // find the one that maps to us, if its already started, no need to do anything...
                        // the shard might already be started since the nodes that is starting the shards might get cluster events
                        // with the shard still initializing, and it will try and start it again (until the verification comes)
                        IndexShardRoutingTable indexShardRoutingTable = indexRoutingTable.shard(shardRouting.id());
                        for (ShardRouting entry : indexShardRoutingTable) {
                            if (shardRouting.currentNodeId().equals(entry.currentNodeId())) {
                                // we found the same shard that exists on the same node id
                                if (entry.started()) {
                                    // already started, do nothing here...
View Full Code Here

        // we use set here and not identity set since we might get duplicates
        HashSet<ShardIterator> set = new HashSet<ShardIterator>();
        IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
        for (String r : routing) {
            int shardId = shardId(clusterState, index, null, null, r);
            IndexShardRoutingTable indexShard = indexRouting.shard(shardId);
            if (indexShard == null) {
                throw new IndexShardMissingException(new ShardId(index, shardId));
            }
            set.add(indexShard.shardsRandomIt());
        }
        return new GroupShardsIterator(set);
    }
View Full Code Here

                IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
                Set<String> effectiveRouting = routing.get(index);
                if (effectiveRouting != null) {
                    for (String r : effectiveRouting) {
                        int shardId = shardId(clusterState, index, null, null, r);
                        IndexShardRoutingTable indexShard = indexRouting.shard(shardId);
                        if (indexShard == null) {
                            throw new IndexShardMissingException(new ShardId(index, shardId));
                        }
                        // we might get duplicates, but that's ok, its an estimated count? (we just want to know if its 1 or not)
                        set.add(indexShard.shardId());
                    }
                }
            }
            return set.size();
        } else {
View Full Code Here

                IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
                Set<String> effectiveRouting = routing.get(index);
                if (effectiveRouting != null) {
                    for (String r : effectiveRouting) {
                        int shardId = shardId(clusterState, index, null, null, r);
                        IndexShardRoutingTable indexShard = indexRouting.shard(shardId);
                        if (indexShard == null) {
                            throw new IndexShardMissingException(new ShardId(index, shardId));
                        }
                        // we might get duplicates, but that's ok, they will override one another
                        set.add(preferenceActiveShardIterator(indexShard, clusterState.nodes().localNodeId(), preference));
View Full Code Here

        int shardId = shardId(clusterState, index, type, id, routing);
        return shards(clusterState, index, shardId);
    }

    protected IndexShardRoutingTable shards(ClusterState clusterState, String index, int shardId) {
        IndexShardRoutingTable indexShard = indexRoutingTable(clusterState, index).shard(shardId);
        if (indexShard == null) {
            throw new IndexShardMissingException(new ShardId(index, shardId));
        }
        return indexShard;
    }
View Full Code Here

        prevRoutingTable = routingTable;
        routingTable = strategy.reroute(clusterState).routingTable();
        clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();

        logger.info("find the replica shard that gets relocated");
        IndexShardRoutingTable indexShardRoutingTable = null;
        if (routingTable.index("test").shard(0).replicaShards().get(0).relocating()) {
            indexShardRoutingTable = routingTable.index("test").shard(0);
        } else if (routingTable.index("test").shard(1).replicaShards().get(0).relocating()) {
            indexShardRoutingTable = routingTable.index("test").shard(1);
        }

        assertThat("failed to find relocating replica", indexShardRoutingTable, notNullValue());

        logger.info("kill the node [{}] of the primary shard for the relocating replica", indexShardRoutingTable.primaryShard().currentNodeId());
        clusterState = newClusterStateBuilder().state(clusterState).nodes(newNodesBuilder().putAll(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build();
        prevRoutingTable = routingTable;
        routingTable = strategy.reroute(clusterState).routingTable();
        clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();

        logger.info("make sure all the primary shards are active");
View Full Code Here

        prevRoutingTable = routingTable;
        routingTable = strategy.reroute(clusterState).routingTable();
        clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();

        logger.info("find the replica shard that gets relocated");
        IndexShardRoutingTable indexShardRoutingTable = null;
        if (routingTable.index("test").shard(0).replicaShards().get(0).relocating()) {
            indexShardRoutingTable = routingTable.index("test").shard(0);
        } else if (routingTable.index("test").shard(1).replicaShards().get(0).relocating()) {
            indexShardRoutingTable = routingTable.index("test").shard(1);
        }

        // we might have primary relocating, and the test is only for replicas, so only test in the case of replica allocation
        if (indexShardRoutingTable != null) {
            logger.info("kill the node [{}] of the primary shard for the relocating replica", indexShardRoutingTable.primaryShard().currentNodeId());
            clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build();
            prevRoutingTable = routingTable;
            routingTable = strategy.reroute(clusterState).routingTable();
            clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();

            logger.info("make sure all the primary shards are active");
View Full Code Here

        // we use set here and not identity set since we might get duplicates
        HashSet<ShardIterator> set = new HashSet<>();
        IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
        for (String r : routing) {
            int shardId = shardId(clusterState, index, null, null, r);
            IndexShardRoutingTable indexShard = indexRouting.shard(shardId);
            if (indexShard == null) {
                throw new IndexShardMissingException(new ShardId(index, shardId));
            }
            set.add(indexShard.shardsRandomIt());
        }
        return new GroupShardsIterator(Lists.newArrayList(set));
    }
View Full Code Here

            final IndexRoutingTable indexRouting = indexRoutingTable(clusterState, index);
            final Set<String> effectiveRouting = routing.get(index);
            if (effectiveRouting != null) {
                for (String r : effectiveRouting) {
                    int shardId = shardId(clusterState, index, null, null, r);
                    IndexShardRoutingTable indexShard = indexRouting.shard(shardId);
                    if (indexShard == null) {
                        throw new IndexShardMissingException(new ShardId(index, shardId));
                    }
                    // we might get duplicates, but that's ok, they will override one another
                    set.add(indexShard);
View Full Code Here

TOP

Related Classes of org.elasticsearch.cluster.routing.IndexShardRoutingTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.