Search in sources :

Example 61 with IndexService

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

the class TermVectorsServiceTests method testTook.

public void testTook() throws Exception {
    XContentBuilder mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field").field("type", "text").field("term_vector", "with_positions_offsets_payloads").endObject().endObject().endObject().endObject();
    createIndex("test", Settings.EMPTY, "type1", mapping);
    ensureGreen();
    client().prepareIndex("test", "type1", "0").setSource("field", "foo bar").setRefreshPolicy(IMMEDIATE).get();
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService test = indicesService.indexService(resolveIndex("test"));
    IndexShard shard = test.getShardOrNull(0);
    assertThat(shard, notNullValue());
    List<Long> longs = Stream.of(abs(randomLong()), abs(randomLong())).sorted().collect(toList());
    TermVectorsRequest request = new TermVectorsRequest("test", "type1", "0");
    TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request, longs.iterator()::next);
    assertThat(response, notNullValue());
    assertThat(response.getTookInMillis(), equalTo(TimeUnit.NANOSECONDS.toMillis(longs.get(1) - longs.get(0))));
}
Also used : TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) TermVectorsResponse(org.elasticsearch.action.termvectors.TermVectorsResponse) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 62 with IndexService

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

the class IndicesServiceTests method testCanDeleteShardContent.

public void testCanDeleteShardContent() {
    IndicesService indicesService = getIndicesService();
    IndexMetaData meta = IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).build();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", meta.getSettings());
    ShardId shardId = new ShardId(meta.getIndex(), 0);
    assertEquals("no shard location", indicesService.canDeleteShardContent(shardId, indexSettings), ShardDeletionCheckResult.NO_FOLDER_FOUND);
    IndexService test = createIndex("test");
    shardId = new ShardId(test.index(), 0);
    assertTrue(test.hasShard(0));
    assertEquals("shard is allocated", indicesService.canDeleteShardContent(shardId, test.getIndexSettings()), ShardDeletionCheckResult.STILL_ALLOCATED);
    test.removeShard(0, "boom");
    assertEquals("shard is removed", indicesService.canDeleteShardContent(shardId, test.getIndexSettings()), ShardDeletionCheckResult.FOLDER_FOUND_CAN_DELETE);
    ShardId notAllocated = new ShardId(test.index(), 100);
    assertEquals("shard that was never on this node should NOT be deletable", indicesService.canDeleteShardContent(notAllocated, test.getIndexSettings()), ShardDeletionCheckResult.NO_FOLDER_FOUND);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexService(org.elasticsearch.index.IndexService) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 63 with IndexService

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

the class IndexingMemoryControllerTests method testActiveInactive.

public void testActiveInactive() {
    createIndex("test", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build());
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService test = indicesService.indexService(resolveIndex("test"));
    MockController controller = new MockController(Settings.builder().put("indices.memory.index_buffer_size", "5mb").build());
    IndexShard shard0 = test.getShard(0);
    controller.simulateIndexing(shard0);
    IndexShard shard1 = test.getShard(1);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 1);
    controller.assertBuffer(shard1, 1);
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard0, 2);
    controller.assertBuffer(shard1, 2);
    // index into one shard only, crosses the 5mb limit, so shard1 is refreshed
    controller.simulateIndexing(shard0);
    controller.simulateIndexing(shard0);
    controller.assertBuffer(shard0, 0);
    controller.assertBuffer(shard1, 2);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    controller.assertBuffer(shard1, 4);
    controller.simulateIndexing(shard1);
    controller.simulateIndexing(shard1);
    // shard1 crossed 5 mb and is now cleared:
    controller.assertBuffer(shard1, 0);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 64 with IndexService

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

the class TransportTermVectorsAction method shardOperation.

@Override
protected TermVectorsResponse shardOperation(TermVectorsRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    return TermVectorsService.getTermVectors(indexShard, request);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard)

Example 65 with IndexService

use of org.elasticsearch.index.IndexService in project crate by crate.

the class SysShardsExpressionsTest method mockIndexShard.

private IndexShard mockIndexShard() {
    IndexService indexService = mock(IndexService.class);
    Index index = new Index(indexName);
    ShardId shardId = new ShardId(indexName, 1);
    IndexShard indexShard = mock(IndexShard.class);
    when(indexService.index()).thenReturn(index);
    when(indexShard.indexService()).thenReturn(indexService);
    when(indexShard.shardId()).thenReturn(shardId);
    when(indexShard.state()).thenReturn(IndexShardState.STARTED);
    StoreStats storeStats = mock(StoreStats.class);
    when(storeStats.getSizeInBytes()).thenReturn(123456L);
    when(indexShard.storeStats()).thenReturn(storeStats);
    Path dataPath = Paths.get("/dummy/" + indexName + "/1");
    when(indexShard.shardPath()).thenReturn(new ShardPath(false, dataPath, dataPath, "123", shardId));
    DocsStats docsStats = new DocsStats(654321L, 0L);
    when(indexShard.docStats()).thenReturn(docsStats).thenThrow(IllegalIndexShardStateException.class);
    ShardRouting shardRouting = ShardRouting.newUnassigned(index.name(), shardId.id(), null, true, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    ShardRoutingHelper.initialize(shardRouting, "node1");
    ShardRoutingHelper.moveToStarted(shardRouting);
    ShardRoutingHelper.relocate(shardRouting, "node_X");
    when(indexShard.routingEntry()).thenReturn(shardRouting);
    when(indexShard.minimumCompatibleVersion()).thenReturn(Version.LATEST);
    RecoveryState recoveryState = mock(RecoveryState.class);
    when(indexShard.recoveryState()).thenReturn(recoveryState);
    RecoveryState.Index recoveryStateIndex = mock(RecoveryState.Index.class);
    RecoveryState.Timer recoveryStateTimer = mock(RecoveryState.Timer.class);
    when(recoveryState.getIndex()).thenReturn(recoveryStateIndex);
    when(recoveryState.getStage()).thenReturn(RecoveryState.Stage.DONE);
    when(recoveryState.getTimer()).thenReturn(recoveryStateTimer);
    when(recoveryState.getType()).thenReturn(RecoveryState.Type.REPLICA);
    when(recoveryStateIndex.totalBytes()).thenReturn(2048L);
    when(recoveryStateIndex.reusedBytes()).thenReturn(1024L);
    when(recoveryStateIndex.recoveredBytes()).thenReturn(1024L);
    when(recoveryStateIndex.totalFileCount()).thenReturn(2);
    when(recoveryStateIndex.reusedFileCount()).thenReturn(1);
    when(recoveryStateIndex.recoveredFileCount()).thenReturn(1);
    when(recoveryStateTimer.time()).thenReturn(10000L);
    return indexShard;
}
Also used : Path(java.nio.file.Path) StoreStats(org.elasticsearch.index.store.StoreStats) IndexService(org.elasticsearch.index.IndexService) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) Index(org.elasticsearch.index.Index) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Aggregations

IndexService (org.elasticsearch.index.IndexService)173 IndexShard (org.elasticsearch.index.shard.IndexShard)53 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)49 IndicesService (org.elasticsearch.indices.IndicesService)38 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)30 Settings (org.elasticsearch.common.settings.Settings)25 ShardId (org.elasticsearch.index.shard.ShardId)24 Index (org.elasticsearch.index.Index)20 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)17 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)14 ClusterState (org.elasticsearch.cluster.ClusterState)13 Map (java.util.Map)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)11 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)11 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)11 List (java.util.List)10