Search in sources :

Example 61 with Index

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

the class AsyncBulkByScrollActionTests method testBulkResponseSetsLotsOfStatus.

public void testBulkResponseSetsLotsOfStatus() {
    testRequest.setAbortOnVersionConflict(false);
    int maxBatches = randomIntBetween(0, 100);
    long versionConflicts = 0;
    long created = 0;
    long updated = 0;
    long deleted = 0;
    for (int batches = 0; batches < maxBatches; batches++) {
        BulkItemResponse[] responses = new BulkItemResponse[randomIntBetween(0, 100)];
        for (int i = 0; i < responses.length; i++) {
            ShardId shardId = new ShardId(new Index("name", "uid"), 0);
            if (rarely()) {
                versionConflicts++;
                responses[i] = new BulkItemResponse(i, randomFrom(DocWriteRequest.OpType.values()), new Failure(shardId.getIndexName(), "type", "id" + i, new VersionConflictEngineException(shardId, "type", "id", "test")));
                continue;
            }
            boolean createdResponse;
            DocWriteRequest.OpType opType;
            switch(randomIntBetween(0, 2)) {
                case 0:
                    createdResponse = true;
                    opType = DocWriteRequest.OpType.CREATE;
                    created++;
                    break;
                case 1:
                    createdResponse = false;
                    opType = randomFrom(DocWriteRequest.OpType.INDEX, DocWriteRequest.OpType.UPDATE);
                    updated++;
                    break;
                case 2:
                    createdResponse = false;
                    opType = DocWriteRequest.OpType.DELETE;
                    deleted++;
                    break;
                default:
                    throw new RuntimeException("Bad scenario");
            }
            responses[i] = new BulkItemResponse(i, opType, new IndexResponse(shardId, "type", "id" + i, randomInt(20), randomInt(), createdResponse));
        }
        new DummyAsyncBulkByScrollAction().onBulkResponse(timeValueNanos(System.nanoTime()), new BulkResponse(responses, 0));
        assertEquals(versionConflicts, testTask.getStatus().getVersionConflicts());
        assertEquals(updated, testTask.getStatus().getUpdated());
        assertEquals(created, testTask.getStatus().getCreated());
        assertEquals(deleted, testTask.getStatus().getDeleted());
        assertEquals(versionConflicts, testTask.getStatus().getVersionConflicts());
    }
}
Also used : BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) Index(org.elasticsearch.index.Index) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ShardId(org.elasticsearch.index.shard.ShardId) VersionConflictEngineException(org.elasticsearch.index.engine.VersionConflictEngineException) IndexResponse(org.elasticsearch.action.index.IndexResponse) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) SearchFailure(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure)

Example 62 with Index

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

the class DiskUsageTests method testFillShardLevelInfo.

public void testFillShardLevelInfo() {
    final Index index = new Index("test", "0xdeadbeef");
    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_0 = ShardRoutingHelper.initialize(test_0, "node1");
    test_0 = ShardRoutingHelper.moveToStarted(test_0);
    Path test0Path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("0");
    CommonStats commonStats0 = new CommonStats();
    commonStats0.store = new StoreStats(100);
    ShardRouting test_1 = ShardRouting.newUnassigned(new ShardId(index, 1), false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    test_1 = ShardRoutingHelper.initialize(test_1, "node2");
    test_1 = ShardRoutingHelper.moveToStarted(test_1);
    Path test1Path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve("1");
    CommonStats commonStats1 = new CommonStats();
    commonStats1.store = new StoreStats(1000);
    ShardStats[] stats = new ShardStats[] { new ShardStats(test_0, new ShardPath(false, test0Path, test0Path, test_0.shardId()), commonStats0, null, null), new ShardStats(test_1, new ShardPath(false, test1Path, test1Path, test_1.shardId()), commonStats1, null, null) };
    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    ImmutableOpenMap.Builder<ShardRouting, String> routingToPath = ImmutableOpenMap.builder();
    ClusterState state = ClusterState.builder(new ClusterName("blarg")).version(0).build();
    InternalClusterInfoService.buildShardLevelInfo(logger, stats, shardSizes, routingToPath, state);
    assertEquals(2, shardSizes.size());
    assertTrue(shardSizes.containsKey(ClusterInfo.shardIdentifierFromRouting(test_0)));
    assertTrue(shardSizes.containsKey(ClusterInfo.shardIdentifierFromRouting(test_1)));
    assertEquals(100L, shardSizes.get(ClusterInfo.shardIdentifierFromRouting(test_0)).longValue());
    assertEquals(1000L, shardSizes.get(ClusterInfo.shardIdentifierFromRouting(test_1)).longValue());
    assertEquals(2, routingToPath.size());
    assertTrue(routingToPath.containsKey(test_0));
    assertTrue(routingToPath.containsKey(test_1));
    assertEquals(test0Path.getParent().getParent().getParent().toAbsolutePath().toString(), routingToPath.get(test_0));
    assertEquals(test1Path.getParent().getParent().getParent().toAbsolutePath().toString(), routingToPath.get(test_1));
}
Also used : Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) StoreStats(org.elasticsearch.index.store.StoreStats) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) Index(org.elasticsearch.index.Index) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ShardId(org.elasticsearch.index.shard.ShardId) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) ShardPath(org.elasticsearch.index.shard.ShardPath) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 63 with Index

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

the class ClusterChangedEventTests method testIndexMetaDataChange.

/**
     * Test the index metadata change check.
     */
public void testIndexMetaDataChange() {
    final int numNodesInCluster = 3;
    final ClusterState state = createState(numNodesInCluster, randomBoolean(), initialIndices);
    // test when its not the same IndexMetaData
    final Index index = initialIndices.get(0);
    final IndexMetaData originalIndexMeta = state.metaData().index(index);
    // make sure the metadata is actually on the cluster state
    assertNotNull("IndexMetaData for " + index + " should exist on the cluster state", originalIndexMeta);
    IndexMetaData newIndexMeta = createIndexMetadata(index, originalIndexMeta.getVersion() + 1);
    assertTrue("IndexMetaData with different version numbers must be considered changed", ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, newIndexMeta));
    // test when it doesn't exist
    newIndexMeta = createIndexMetadata(new Index("doesntexist", UUIDs.randomBase64UUID()));
    assertTrue("IndexMetaData that didn't previously exist should be considered changed", ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, newIndexMeta));
    // test when its the same IndexMetaData
    assertFalse("IndexMetaData should be the same", ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, originalIndexMeta));
}
Also used : Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 64 with Index

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

the class StartedShardsRoutingTests method testStartedShardsMatching.

public void testStartedShardsMatching() {
    AllocationService allocation = createAllocationService();
    logger.info("--> building initial cluster state");
    AllocationId allocationId = AllocationId.newRelocation(AllocationId.newInitializing());
    final IndexMetaData indexMetaData = IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(0).putInSyncAllocationIds(1, Collections.singleton(allocationId.getId())).build();
    final Index index = indexMetaData.getIndex();
    ClusterState.Builder stateBuilder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).metaData(MetaData.builder().put(indexMetaData, false));
    final ShardRouting initShard = TestShardRouting.newShardRouting(new ShardId(index, 0), "node1", true, ShardRoutingState.INITIALIZING);
    final ShardRouting relocatingShard = TestShardRouting.newShardRouting(new ShardId(index, 1), "node1", "node2", true, ShardRoutingState.RELOCATING, allocationId);
    stateBuilder.routingTable(RoutingTable.builder().add(IndexRoutingTable.builder(index).addIndexShard(new IndexShardRoutingTable.Builder(initShard.shardId()).addShard(initShard).build()).addIndexShard(new IndexShardRoutingTable.Builder(relocatingShard.shardId()).addShard(relocatingShard).build())).build());
    ClusterState state = stateBuilder.build();
    logger.info("--> test starting of shard");
    ClusterState newState = allocation.applyStartedShards(state, Arrays.asList(initShard));
    assertThat("failed to start " + initShard + "\ncurrent routing table:" + newState.routingTable(), newState, not(equalTo(state)));
    assertTrue(initShard + "isn't started \ncurrent routing table:" + newState.routingTable(), newState.routingTable().index("test").shard(initShard.id()).allShardsStarted());
    state = newState;
    logger.info("--> testing starting of relocating shards");
    newState = allocation.applyStartedShards(state, Arrays.asList(relocatingShard.getTargetRelocatingShard()));
    assertThat("failed to start " + relocatingShard + "\ncurrent routing table:" + newState.routingTable(), newState, not(equalTo(state)));
    ShardRouting shardRouting = newState.routingTable().index("test").shard(relocatingShard.id()).getShards().get(0);
    assertThat(shardRouting.state(), equalTo(ShardRoutingState.STARTED));
    assertThat(shardRouting.currentNodeId(), equalTo("node2"));
    assertThat(shardRouting.relocatingNodeId(), nullValue());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterState(org.elasticsearch.cluster.ClusterState) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) AllocationId(org.elasticsearch.cluster.routing.AllocationId) Index(org.elasticsearch.index.Index) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 65 with Index

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

the class ThrottlingAllocationTests method createRecoveryStateAndInitalizeAllocations.

private ClusterState createRecoveryStateAndInitalizeAllocations(MetaData metaData, TestGatewayAllocator gatewayAllocator) {
    DiscoveryNode node1 = newNode("node1");
    MetaData.Builder metaDataBuilder = new MetaData.Builder(metaData);
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
    for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
        Index index = cursor.value.getIndex();
        IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(cursor.value);
        final int recoveryType = randomInt(5);
        if (recoveryType <= 4) {
            addInSyncAllocationIds(index, indexMetaDataBuilder, gatewayAllocator, node1);
        }
        IndexMetaData indexMetaData = indexMetaDataBuilder.build();
        metaDataBuilder.put(indexMetaData, false);
        switch(recoveryType) {
            case 0:
                routingTableBuilder.addAsRecovery(indexMetaData);
                break;
            case 1:
                routingTableBuilder.addAsFromCloseToOpen(indexMetaData);
                break;
            case 2:
                routingTableBuilder.addAsFromDangling(indexMetaData);
                break;
            case 3:
                routingTableBuilder.addAsNewRestore(indexMetaData, new SnapshotRecoverySource(new Snapshot("repo", new SnapshotId("snap", "randomId")), Version.CURRENT, indexMetaData.getIndex().getName()), new IntHashSet());
                break;
            case 4:
                routingTableBuilder.addAsRestore(indexMetaData, new SnapshotRecoverySource(new Snapshot("repo", new SnapshotId("snap", "randomId")), Version.CURRENT, indexMetaData.getIndex().getName()));
                break;
            case 5:
                routingTableBuilder.addAsNew(indexMetaData);
                break;
            default:
                throw new IndexOutOfBoundsException();
        }
    }
    return ClusterState.builder(CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(DiscoveryNodes.builder().add(node1)).metaData(metaDataBuilder.build()).routingTable(routingTableBuilder.build()).build();
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IntHashSet(com.carrotsearch.hppc.IntHashSet) Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

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