use of org.elasticsearch.indices.IndicesService in project elasticsearch by elastic.
the class IndexShardIT method testShardHasMemoryBufferOnTranslogRecover.
public void testShardHasMemoryBufferOnTranslogRecover() throws Throwable {
createIndex("test");
ensureGreen();
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexService indexService = indicesService.indexService(resolveIndex("test"));
IndexShard shard = indexService.getShardOrNull(0);
client().prepareIndex("test", "test", "0").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
client().prepareDelete("test", "test", "0").get();
client().prepareIndex("test", "test", "1").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {
};
shard.close("simon says", false);
AtomicReference<IndexShard> shardRef = new AtomicReference<>();
List<Exception> failures = new ArrayList<>();
IndexingOperationListener listener = new IndexingOperationListener() {
@Override
public void postIndex(ShardId shardId, Engine.Index index, Engine.IndexResult result) {
try {
assertNotNull(shardRef.get());
// this is all IMC needs to do - check current memory and refresh
assertTrue(shardRef.get().getIndexBufferRAMBytesUsed() > 0);
shardRef.get().refresh("test");
} catch (Exception e) {
failures.add(e);
throw e;
}
}
@Override
public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResult result) {
try {
assertNotNull(shardRef.get());
// this is all IMC needs to do - check current memory and refresh
assertTrue(shardRef.get().getIndexBufferRAMBytesUsed() > 0);
shardRef.get().refresh("test");
} catch (Exception e) {
failures.add(e);
throw e;
}
}
};
final IndexShard newShard = newIndexShard(indexService, shard, wrapper, listener);
shardRef.set(newShard);
recoverShard(newShard);
try {
ExceptionsHelper.rethrowAndSuppress(failures);
} finally {
newShard.close("just do it", randomBoolean());
}
}
use of org.elasticsearch.indices.IndicesService 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.indices.IndicesService in project elasticsearch by elastic.
the class InternalTestCluster method assertSameSyncIdSameDocs.
private void assertSameSyncIdSameDocs() {
Map<String, Long> docsOnShards = new HashMap<>();
final Collection<NodeAndClient> nodesAndClients = nodes.values();
for (NodeAndClient nodeAndClient : nodesAndClients) {
IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name);
for (IndexService indexService : indexServices) {
for (IndexShard indexShard : indexService) {
CommitStats commitStats = indexShard.commitStats();
if (commitStats != null) {
// null if the engine is closed or if the shard is recovering
String syncId = commitStats.getUserData().get(Engine.SYNC_COMMIT_ID);
if (syncId != null) {
long liveDocsOnShard = commitStats.getNumDocs();
if (docsOnShards.get(syncId) != null) {
assertThat("sync id is equal but number of docs does not match on node " + nodeAndClient.name + ". expected " + docsOnShards.get(syncId) + " but got " + liveDocsOnShard, docsOnShards.get(syncId), equalTo(liveDocsOnShard));
} else {
docsOnShards.put(syncId, liveDocsOnShard);
}
}
}
}
}
}
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class ArrayMapperTest method mapper.
/**
* create index with type and mapping and validate DocumentMapper serialization
*/
private DocumentMapper mapper(String indexName, String type, String mapping) throws IOException {
// we serialize and deserialize the mapping to make sure serialization works just fine
client().admin().indices().prepareCreate(indexName).addMapping(type, mapping).setSettings(Settings.builder().put("number_of_replicas", 0).build()).execute().actionGet();
client().admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setWaitForRelocatingShards(0).setWaitForEvents(Priority.LANGUID).execute().actionGet();
IndicesService instanceFromNode = internalCluster().getInstance(IndicesService.class);
IndexService indexService = instanceFromNode.indexServiceSafe(indexName);
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
DocumentMapper defaultMapper = parser.parse(type, new CompressedXContent(mapping));
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.startObject();
defaultMapper.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String rebuildMapping = builder.string();
return parser.parse(type, new CompressedXContent(rebuildMapping));
}
use of org.elasticsearch.indices.IndicesService in project crate by crate.
the class TransportShardDeleteActionTest method prepare.
@Before
public void prepare() throws Exception {
IndicesService indicesService = mock(IndicesService.class);
IndexService indexService = mock(IndexService.class);
when(indicesService.indexServiceSafe(TABLE_IDENT.indexName())).thenReturn(indexService);
indexShard = mock(IndexShard.class);
when(indexService.shardSafe(0)).thenReturn(indexShard);
transportShardDeleteAction = new TransportShardDeleteAction(Settings.EMPTY, mock(TransportService.class), mock(MappingUpdatedAction.class), mock(IndexNameExpressionResolver.class), mock(ClusterService.class), indicesService, mock(ThreadPool.class), mock(ShardStateAction.class), mock(ActionFilters.class));
}
Aggregations