Search in sources :

Example 6 with Index

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

the class RoutingTableTests method testDistinctNodes.

public void testDistinctNodes() {
    ShardId shardId = new ShardId(new Index("index", "uuid"), 0);
    ShardRouting routing1 = TestShardRouting.newShardRouting(shardId, "node1", randomBoolean(), ShardRoutingState.STARTED);
    ShardRouting routing2 = TestShardRouting.newShardRouting(shardId, "node2", randomBoolean(), ShardRoutingState.STARTED);
    ShardRouting routing3 = TestShardRouting.newShardRouting(shardId, "node1", randomBoolean(), ShardRoutingState.STARTED);
    ShardRouting routing4 = TestShardRouting.newShardRouting(shardId, "node3", "node2", randomBoolean(), ShardRoutingState.RELOCATING);
    assertTrue(IndexShardRoutingTable.Builder.distinctNodes(Arrays.asList(routing1, routing2)));
    assertFalse(IndexShardRoutingTable.Builder.distinctNodes(Arrays.asList(routing1, routing3)));
    assertFalse(IndexShardRoutingTable.Builder.distinctNodes(Arrays.asList(routing1, routing2, routing3)));
    assertTrue(IndexShardRoutingTable.Builder.distinctNodes(Arrays.asList(routing1, routing4)));
    assertFalse(IndexShardRoutingTable.Builder.distinctNodes(Arrays.asList(routing2, routing4)));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Index(org.elasticsearch.index.Index)

Example 7 with Index

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

the class ShardRoutingTests method testEqualsIgnoringVersion.

public void testEqualsIgnoringVersion() {
    ShardRouting routing = randomShardRouting("test", 0);
    ShardRouting otherRouting = routing;
    Integer[] changeIds = new Integer[] { 0, 1, 2, 3, 4, 5, 6 };
    for (int changeId : randomSubsetOf(randomIntBetween(1, changeIds.length), changeIds)) {
        boolean unchanged = false;
        switch(changeId) {
            case 0:
                // change index
                ShardId shardId = new ShardId(new Index("blubb", randomAsciiOfLength(10)), otherRouting.id());
                otherRouting = new ShardRouting(shardId, otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 1:
                // change shard id
                otherRouting = new ShardRouting(new ShardId(otherRouting.index(), otherRouting.id() + 1), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 2:
                // change current node
                otherRouting = new ShardRouting(otherRouting.shardId(), otherRouting.currentNodeId() == null ? "1" : otherRouting.currentNodeId() + "_1", otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 3:
                // change relocating node
                otherRouting = new ShardRouting(otherRouting.shardId(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId() == null ? "1" : otherRouting.relocatingNodeId() + "_1", otherRouting.primary(), otherRouting.state(), otherRouting.recoverySource(), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                break;
            case 4:
                // change recovery source (only works for inactive primaries)
                if (otherRouting.active() || otherRouting.primary() == false) {
                    unchanged = true;
                } else {
                    otherRouting = new ShardRouting(otherRouting.shardId(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), new RecoverySource.SnapshotRecoverySource(new Snapshot("test", new SnapshotId("s1", UUIDs.randomBase64UUID())), Version.CURRENT, "test"), otherRouting.unassignedInfo(), otherRouting.allocationId(), otherRouting.getExpectedShardSize());
                }
                break;
            case 5:
                // change primary flag
                otherRouting = TestShardRouting.newShardRouting(otherRouting.getIndexName(), otherRouting.id(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary() == false, otherRouting.state(), otherRouting.unassignedInfo());
                break;
            case 6:
                // change state
                ShardRoutingState newState;
                do {
                    newState = randomFrom(ShardRoutingState.values());
                } while (newState == otherRouting.state());
                UnassignedInfo unassignedInfo = otherRouting.unassignedInfo();
                if (unassignedInfo == null && (newState == ShardRoutingState.UNASSIGNED || newState == ShardRoutingState.INITIALIZING)) {
                    unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test");
                }
                otherRouting = TestShardRouting.newShardRouting(otherRouting.getIndexName(), otherRouting.id(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), newState, unassignedInfo);
                break;
        }
        if (randomBoolean()) {
            // change unassigned info
            otherRouting = TestShardRouting.newShardRouting(otherRouting.getIndexName(), otherRouting.id(), otherRouting.currentNodeId(), otherRouting.relocatingNodeId(), otherRouting.primary(), otherRouting.state(), otherRouting.unassignedInfo() == null ? new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test") : new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, otherRouting.unassignedInfo().getMessage() + "_1"));
        }
        if (unchanged == false) {
            logger.debug("comparing\nthis  {} to\nother {}", routing, otherRouting);
            assertFalse("expected non-equality\nthis  " + routing + ",\nother " + otherRouting, routing.equalsIgnoringMetaData(otherRouting));
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) Index(org.elasticsearch.index.Index)

Example 8 with Index

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

the class GroupShardsIteratorTests method testSize.

public void testSize() {
    List<ShardIterator> list = new ArrayList<>();
    Index index = new Index("foo", "na");
    list.add(new PlainShardIterator(new ShardId(index, 0), Arrays.asList(newRouting(index, 0, true), newRouting(index, 0, true), newRouting(index, 0, true))));
    list.add(new PlainShardIterator(new ShardId(index, 1), Collections.emptyList()));
    list.add(new PlainShardIterator(new ShardId(index, 2), Arrays.asList(newRouting(index, 2, true))));
    index = new Index("foo_1", "na");
    list.add(new PlainShardIterator(new ShardId(index, 0), Arrays.asList(newRouting(index, 0, true))));
    list.add(new PlainShardIterator(new ShardId(index, 1), Arrays.asList(newRouting(index, 1, true))));
    GroupShardsIterator iter = new GroupShardsIterator(list);
    assertEquals(7, iter.totalSizeWith1ForEmpty());
    assertEquals(5, iter.size());
    assertEquals(6, iter.totalSize());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index)

Example 9 with Index

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

the class MetaDataTests method testMetaDataGlobalStateChangesOnIndexDeletions.

public void testMetaDataGlobalStateChangesOnIndexDeletions() {
    IndexGraveyard.Builder builder = IndexGraveyard.builder();
    builder.addTombstone(new Index("idx1", UUIDs.randomBase64UUID()));
    final MetaData metaData1 = MetaData.builder().indexGraveyard(builder.build()).build();
    builder = IndexGraveyard.builder(metaData1.indexGraveyard());
    builder.addTombstone(new Index("idx2", UUIDs.randomBase64UUID()));
    final MetaData metaData2 = MetaData.builder(metaData1).indexGraveyard(builder.build()).build();
    assertFalse("metadata not equal after adding index deletions", MetaData.isGlobalStateEquals(metaData1, metaData2));
    final MetaData metaData3 = MetaData.builder(metaData2).build();
    assertTrue("metadata equal when not adding index deletions", MetaData.isGlobalStateEquals(metaData2, metaData3));
}
Also used : Index(org.elasticsearch.index.Index)

Example 10 with Index

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

the class FlushIT method testSyncedFlush.

public void testSyncedFlush() throws ExecutionException, InterruptedException, IOException {
    internalCluster().ensureAtLeastNumDataNodes(2);
    prepareCreate("test").setSettings(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).get();
    ensureGreen();
    final Index index = client().admin().cluster().prepareState().get().getState().metaData().index("test").getIndex();
    IndexStats indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    ShardsSyncedFlushResult result;
    if (randomBoolean()) {
        logger.info("--> sync flushing shard 0");
        result = SyncedFlushUtil.attemptSyncedFlush(internalCluster(), new ShardId(index, 0));
    } else {
        logger.info("--> sync flushing index [test]");
        SyncedFlushResponse indicesResult = client().admin().indices().prepareSyncedFlush("test").get();
        result = indicesResult.getShardsResultPerIndex().get("test").get(0);
    }
    assertFalse(result.failed());
    assertThat(result.totalShards(), equalTo(indexStats.getShards().length));
    assertThat(result.successfulShards(), equalTo(indexStats.getShards().length));
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    String syncId = result.syncId();
    for (ShardStats shardStats : indexStats.getShards()) {
        final String shardSyncId = shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID);
        assertThat(shardSyncId, equalTo(syncId));
    }
    // now, start new node and relocate a shard there and see if sync id still there
    String newNodeName = internalCluster().startNode();
    ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
    ShardRouting shardRouting = clusterState.getRoutingTable().index("test").shard(0).iterator().next();
    String currentNodeName = clusterState.nodes().resolveNode(shardRouting.currentNodeId()).getName();
    assertFalse(currentNodeName.equals(newNodeName));
    internalCluster().client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, currentNodeName, newNodeName)).get();
    client().admin().cluster().prepareHealth().setWaitForNoRelocatingShards(true).get();
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build()).get();
    ensureGreen("test");
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, internalCluster().numDataNodes() - 1).build()).get();
    ensureGreen("test");
    indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
    for (ShardStats shardStats : indexStats.getShards()) {
        assertNotNull(shardStats.getCommitStats().getUserData().get(Engine.SYNC_COMMIT_ID));
    }
}
Also used : ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) ShardId(org.elasticsearch.index.shard.ShardId) ClusterState(org.elasticsearch.cluster.ClusterState) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) Index(org.elasticsearch.index.Index) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

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