Search in sources :

Example 41 with UnassignedInfo

use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.

the class PriorityComparatorTests method testPreferPriorityIndices.

public void testPreferPriorityIndices() {
    RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards(mock(RoutingNodes.class));
    List<ShardRouting> shardRoutings = Arrays.asList(TestShardRouting.newShardRouting("oldest", 0, null, null, randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")), TestShardRouting.newShardRouting("newest", 0, null, null, randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")));
    Collections.shuffle(shardRoutings, random());
    for (ShardRouting routing : shardRoutings) {
        shards.add(routing);
    }
    shards.sort(new PriorityComparator() {

        @Override
        protected Settings getIndexSettings(Index index) {
            if ("oldest".equals(index.getName())) {
                return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10).put(IndexMetaData.SETTING_PRIORITY, 100).build();
            } else if ("newest".equals(index.getName())) {
                return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 100).put(IndexMetaData.SETTING_PRIORITY, 1).build();
            }
            return Settings.EMPTY;
        }
    });
    RoutingNodes.UnassignedShards.UnassignedIterator iterator = shards.iterator();
    ShardRouting next = iterator.next();
    assertEquals("oldest", next.getIndexName());
    next = iterator.next();
    assertEquals("newest", next.getIndexName());
    assertFalse(iterator.hasNext());
}
Also used : RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) Index(org.elasticsearch.index.Index) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) Settings(org.elasticsearch.common.settings.Settings)

Example 42 with UnassignedInfo

use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.

the class SearchAsyncActionTests method getShardsIter.

private GroupShardsIterator getShardsIter(String index, int numShards, boolean doReplicas, DiscoveryNode primaryNode, DiscoveryNode replicaNode) {
    ArrayList<ShardIterator> list = new ArrayList<>();
    for (int i = 0; i < numShards; i++) {
        ArrayList<ShardRouting> started = new ArrayList<>();
        ArrayList<ShardRouting> initializing = new ArrayList<>();
        ArrayList<ShardRouting> unassigned = new ArrayList<>();
        ShardRouting routing = ShardRouting.newUnassigned(new ShardId(new Index(index, "_na_"), i), true, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"));
        routing = routing.initialize(primaryNode.getId(), i + "p", 0);
        routing.started();
        started.add(routing);
        if (doReplicas) {
            routing = ShardRouting.newUnassigned(new ShardId(new Index(index, "_na_"), i), false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"));
            if (replicaNode != null) {
                routing = routing.initialize(replicaNode.getId(), i + "r", 0);
                if (randomBoolean()) {
                    routing.started();
                    started.add(routing);
                } else {
                    initializing.add(routing);
                }
            } else {
                // unused yet
                unassigned.add(routing);
            }
        }
        Collections.shuffle(started, random());
        started.addAll(initializing);
        list.add(new PlainShardIterator(new ShardId(new Index(index, "_na_"), i), started));
    }
    return new GroupShardsIterator(list);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) PlainShardIterator(org.elasticsearch.cluster.routing.PlainShardIterator) ArrayList(java.util.ArrayList) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) PlainShardIterator(org.elasticsearch.cluster.routing.PlainShardIterator) Index(org.elasticsearch.index.Index) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 43 with UnassignedInfo

use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.

the class IndexShardIT method getInitializingShardRouting.

private static ShardRouting getInitializingShardRouting(ShardRouting existingShardRouting) {
    ShardRouting shardRouting = TestShardRouting.newShardRouting(existingShardRouting.shardId(), existingShardRouting.currentNodeId(), null, existingShardRouting.primary(), ShardRoutingState.INITIALIZING, existingShardRouting.allocationId());
    shardRouting = shardRouting.updateUnassigned(new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, "fake recovery"), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
    return shardRouting;
}
Also used : UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 44 with UnassignedInfo

use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.

the class ThrottlingAllocationTests method addInSyncAllocationIds.

private void addInSyncAllocationIds(Index index, IndexMetaData.Builder indexMetaData, TestGatewayAllocator gatewayAllocator, DiscoveryNode node1) {
    for (int shard = 0; shard < indexMetaData.numberOfShards(); shard++) {
        final boolean primary = randomBoolean();
        final ShardRouting unassigned = ShardRouting.newUnassigned(new ShardId(index, shard), primary, primary ? RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"));
        ShardRouting started = ShardRoutingHelper.moveToStarted(ShardRoutingHelper.initialize(unassigned, node1.getId()));
        indexMetaData.putInSyncAllocationIds(shard, Collections.singleton(started.allocationId().getId()));
        gatewayAllocator.addKnownAllocation(started);
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 45 with UnassignedInfo

use of org.elasticsearch.cluster.routing.UnassignedInfo in project elasticsearch by elastic.

the class IndicesLifecycleListenerSingleNodeTests method testStartDeleteIndexEventCallback.

public void testStartDeleteIndexEventCallback() throws Throwable {
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    assertAcked(client().admin().indices().prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
    ensureGreen();
    Index idx = resolveIndex("test");
    IndexMetaData metaData = indicesService.indexService(idx).getMetaData();
    ShardRouting shardRouting = indicesService.indexService(idx).getShard(0).routingEntry();
    final AtomicInteger counter = new AtomicInteger(1);
    IndexEventListener countingListener = new IndexEventListener() {

        @Override
        public void beforeIndexCreated(Index index, Settings indexSettings) {
            assertEquals("test", index.getName());
            assertEquals(1, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexCreated(IndexService indexService) {
            assertEquals("test", indexService.index().getName());
            assertEquals(2, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexShardCreated(ShardId shardId, Settings indexSettings) {
            assertEquals(3, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardCreated(IndexShard indexShard) {
            assertEquals(4, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardStarted(IndexShard indexShard) {
            assertEquals(5, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason reason) {
            assertEquals(DELETED, reason);
            assertEquals(6, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexShardDeleted(ShardId shardId, Settings indexSettings) {
            assertEquals(7, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardDeleted(ShardId shardId, Settings indexSettings) {
            assertEquals(8, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexRemoved(Index index, IndexSettings indexSettings, IndexRemovalReason reason) {
            assertEquals(DELETED, reason);
            assertEquals(9, counter.get());
            counter.incrementAndGet();
        }
    };
    indicesService.removeIndex(idx, DELETED, "simon says");
    try {
        IndexService index = indicesService.createIndex(metaData, Arrays.asList(countingListener), s -> {
        });
        assertEquals(3, counter.get());
        idx = index.index();
        ShardRouting newRouting = shardRouting;
        String nodeId = newRouting.currentNodeId();
        UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "boom");
        newRouting = newRouting.moveToUnassigned(unassignedInfo).updateUnassigned(unassignedInfo, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE);
        newRouting = ShardRoutingHelper.initialize(newRouting, nodeId);
        IndexShard shard = index.createShard(newRouting);
        shard.updateRoutingEntry(newRouting);
        assertEquals(5, counter.get());
        final DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
        shard.markAsRecovering("store", new RecoveryState(newRouting, localNode, null));
        shard.recoverFromStore();
        newRouting = ShardRoutingHelper.moveToStarted(newRouting);
        shard.updateRoutingEntry(newRouting);
        assertEquals(6, counter.get());
    } finally {
        indicesService.removeIndex(idx, DELETED, "simon says");
    }
    assertEquals(10, counter.get());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexService(org.elasticsearch.index.IndexService) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) IndexShard(org.elasticsearch.index.shard.IndexShard) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardId(org.elasticsearch.index.shard.ShardId) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexRemovalReason(org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Aggregations

UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)68 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)45 ShardId (org.elasticsearch.index.shard.ShardId)36 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)30 ClusterState (org.elasticsearch.cluster.ClusterState)20 Index (org.elasticsearch.index.Index)19 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)18 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)18 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)18 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)18 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)17 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)16 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ShardRoutingState (org.elasticsearch.cluster.routing.ShardRoutingState)14 AllocateUnassignedDecision (org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision)12 NodeAllocationResult (org.elasticsearch.cluster.routing.allocation.NodeAllocationResult)11 Decision (org.elasticsearch.cluster.routing.allocation.decider.Decision)11 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)11 MetaData (org.elasticsearch.cluster.metadata.MetaData)10