Search in sources :

Example 11 with IndicesService

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());
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) ArrayList(java.util.ArrayList) IndicesService(org.elasticsearch.indices.IndicesService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Index(org.elasticsearch.index.Index) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 12 with IndicesService

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))));
}
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 13 with IndicesService

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) IndexService(org.elasticsearch.index.IndexService) CommitStats(org.elasticsearch.index.engine.CommitStats) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService)

Example 14 with IndicesService

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));
}
Also used : IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) IndicesService(org.elasticsearch.indices.IndicesService) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 15 with IndicesService

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));
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Before(org.junit.Before)

Aggregations

IndicesService (org.elasticsearch.indices.IndicesService)57 IndexService (org.elasticsearch.index.IndexService)41 IndexShard (org.elasticsearch.index.shard.IndexShard)29 Index (org.elasticsearch.index.Index)21 ClusterState (org.elasticsearch.cluster.ClusterState)12 Settings (org.elasticsearch.common.settings.Settings)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 ShardId (org.elasticsearch.index.shard.ShardId)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)7 Test (org.junit.Test)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ActionListener (org.elasticsearch.action.ActionListener)5