Search in sources :

Example 26 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class MetaDataDeleteIndexServiceTests method testDeleteMissing.

public void testDeleteMissing() {
    Index index = new Index("missing", "doesn't matter");
    ClusterState state = ClusterState.builder(ClusterName.DEFAULT).build();
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.deleteIndices(state, singleton(index)));
    assertEquals(index, e.getIndex());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Index(org.elasticsearch.index.Index)

Example 27 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class AckIT method testClusterRerouteAcknowledgement.

public void testClusterRerouteAcknowledgement() throws InterruptedException {
    assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS)).put(SETTING_NUMBER_OF_REPLICAS, 0)));
    ensureGreen();
    MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
    final Index index = client().admin().cluster().prepareState().get().getState().metaData().index("test").getIndex();
    final ShardId commandShard = new ShardId(index, moveAllocationCommand.shardId());
    assertAcked(client().admin().cluster().prepareReroute().add(moveAllocationCommand));
    for (Client client : clients()) {
        ClusterState clusterState = getLocalClusterState(client);
        for (ShardRouting shardRouting : clusterState.getRoutingNodes().node(moveAllocationCommand.fromNode())) {
            //if the shard that we wanted to move is still on the same node, it must be relocating
            if (shardRouting.shardId().equals(commandShard)) {
                assertThat(shardRouting.relocating(), equalTo(true));
            }
        }
        boolean found = false;
        for (ShardRouting shardRouting : clusterState.getRoutingNodes().node(moveAllocationCommand.toNode())) {
            if (shardRouting.shardId().equals(commandShard)) {
                assertThat(shardRouting.state(), anyOf(equalTo(ShardRoutingState.INITIALIZING), equalTo(ShardRoutingState.STARTED)));
                found = true;
                break;
            }
        }
        assertThat(found, equalTo(true));
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterState(org.elasticsearch.cluster.ClusterState) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) AliasOrIndex(org.elasticsearch.cluster.metadata.AliasOrIndex) Index(org.elasticsearch.index.Index) Client(org.elasticsearch.client.Client) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 28 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class AckIT method testClusterRerouteAcknowledgementDryRun.

public void testClusterRerouteAcknowledgementDryRun() throws InterruptedException {
    client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS)).put(SETTING_NUMBER_OF_REPLICAS, 0)).get();
    ensureGreen();
    MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
    final Index index = client().admin().cluster().prepareState().get().getState().metaData().index("test").getIndex();
    final ShardId commandShard = new ShardId(index, moveAllocationCommand.shardId());
    assertAcked(client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand));
    //testing only on master with the latest cluster state as we didn't make any change thus we cannot guarantee that
    //all nodes hold the same cluster state version. We only know there was no need to change anything, thus no need for ack on this update.
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get();
    boolean found = false;
    for (ShardRouting shardRouting : clusterStateResponse.getState().getRoutingNodes().node(moveAllocationCommand.fromNode())) {
        //the shard that we wanted to move is still on the same node, as we had dryRun flag
        if (shardRouting.shardId().equals(commandShard)) {
            assertThat(shardRouting.started(), equalTo(true));
            found = true;
            break;
        }
    }
    assertThat(found, equalTo(true));
    for (ShardRouting shardRouting : clusterStateResponse.getState().getRoutingNodes().node(moveAllocationCommand.toNode())) {
        if (shardRouting.shardId().equals(commandShard)) {
            fail("shard [" + shardRouting + "] shouldn't be on node [" + moveAllocationCommand.toString() + "]");
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) AliasOrIndex(org.elasticsearch.cluster.metadata.AliasOrIndex) Index(org.elasticsearch.index.Index) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 29 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class IndexGraveyardTests method testAddTombstones.

public void testAddTombstones() {
    final IndexGraveyard graveyard1 = createRandom();
    final IndexGraveyard.Builder graveyardBuidler = IndexGraveyard.builder(graveyard1);
    final int numAdds = randomIntBetween(0, 4);
    for (int j = 0; j < numAdds; j++) {
        graveyardBuidler.addTombstone(new Index("nidx-" + j, UUIDs.randomBase64UUID()));
    }
    final IndexGraveyard graveyard2 = graveyardBuidler.build();
    if (numAdds == 0) {
        assertThat(graveyard2, equalTo(graveyard1));
    } else {
        assertThat(graveyard2, not(graveyard1));
        assertThat(graveyard1.getTombstones().size(), lessThan(graveyard2.getTombstones().size()));
        assertThat(Collections.indexOfSubList(graveyard2.getTombstones(), graveyard1.getTombstones()), equalTo(0));
    }
}
Also used : Index(org.elasticsearch.index.Index)

Example 30 with Index

use of org.elasticsearch.index.Index in project elasticsearch by elastic.

the class IndexGraveyardTests method createRandom.

public static IndexGraveyard createRandom() {
    final IndexGraveyard.Builder graveyard = IndexGraveyard.builder();
    final int numTombstones = randomIntBetween(0, 4);
    for (int i = 0; i < numTombstones; i++) {
        graveyard.addTombstone(new Index("idx-" + i, UUIDs.randomBase64UUID()));
    }
    return graveyard.build();
}
Also used : Index(org.elasticsearch.index.Index)

Aggregations

Index (org.elasticsearch.index.Index)366 ShardId (org.elasticsearch.index.shard.ShardId)108 Settings (org.elasticsearch.common.settings.Settings)95 ClusterState (org.elasticsearch.cluster.ClusterState)88 ArrayList (java.util.ArrayList)79 IOException (java.io.IOException)74 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)65 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)65 HashMap (java.util.HashMap)61 Map (java.util.Map)61 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)59 List (java.util.List)56 HashSet (java.util.HashSet)50 Path (java.nio.file.Path)45 IndexSettings (org.elasticsearch.index.IndexSettings)44 IndexService (org.elasticsearch.index.IndexService)43 Set (java.util.Set)40 Metadata (org.elasticsearch.cluster.metadata.Metadata)39 ClusterService (org.elasticsearch.cluster.service.ClusterService)39 ActionListener (org.elasticsearch.action.ActionListener)35