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))));
}
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);
}
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);
}
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);
}
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;
}
Aggregations