Search in sources :

Example 1 with IndexSearcherWrapper

use of org.elasticsearch.index.shard.IndexSearcherWrapper in project elasticsearch by elastic.

the class InternalEngineTests method testIndexSearcherWrapper.

public void testIndexSearcherWrapper() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {

        @Override
        public DirectoryReader wrap(DirectoryReader reader) {
            counter.incrementAndGet();
            return reader;
        }

        @Override
        public IndexSearcher wrap(IndexSearcher searcher) throws EngineException {
            counter.incrementAndGet();
            return searcher;
        }
    };
    Store store = createStore();
    Path translog = createTempDir("translog-test");
    InternalEngine engine = createEngine(store, translog);
    engine.close();
    engine = new InternalEngine(copy(engine.config(), EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG));
    assertTrue(engine.isRecovering());
    engine.recoverFromTranslog();
    Engine.Searcher searcher = wrapper.wrap(engine.acquireSearcher("test"));
    assertThat(counter.get(), equalTo(2));
    searcher.close();
    IOUtils.close(store, engine);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Path(java.nio.file.Path) ContentPath(org.elasticsearch.index.mapper.ContentPath) Searcher(org.elasticsearch.index.engine.Engine.Searcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DirectoryReader(org.apache.lucene.index.DirectoryReader) Store(org.elasticsearch.index.store.Store) IndexSearcherWrapper(org.elasticsearch.index.shard.IndexSearcherWrapper)

Example 2 with IndexSearcherWrapper

use of org.elasticsearch.index.shard.IndexSearcherWrapper in project elasticsearch by elastic.

the class IndexingMemoryControllerTests method testTranslogRecoveryWorksWithIMC.

public void testTranslogRecoveryWorksWithIMC() throws IOException {
    createIndex("test");
    ensureGreen();
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService indexService = indicesService.indexService(resolveIndex("test"));
    IndexShard shard = indexService.getShardOrNull(0);
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("test", "test", Integer.toString(i)).setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
    }
    IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {
    };
    shard.close("simon says", false);
    AtomicReference<IndexShard> shardRef = new AtomicReference<>();
    Settings settings = Settings.builder().put("indices.memory.index_buffer_size", "50kb").build();
    Iterable<IndexShard> iterable = () -> (shardRef.get() == null) ? Collections.<IndexShard>emptyList().iterator() : Collections.singleton(shardRef.get()).iterator();
    AtomicInteger flushes = new AtomicInteger();
    IndexingMemoryController imc = new IndexingMemoryController(settings, client().threadPool(), iterable) {

        @Override
        protected void writeIndexingBufferAsync(IndexShard shard) {
            assertEquals(shard, shardRef.get());
            flushes.incrementAndGet();
            shard.writeIndexingBuffer();
        }
    };
    final IndexShard newShard = IndexShardIT.newIndexShard(indexService, shard, wrapper, imc);
    shardRef.set(newShard);
    try {
        assertEquals(0, imc.availableShards().size());
        ShardRouting routing = newShard.routingEntry();
        DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
        newShard.markAsRecovering("store", new RecoveryState(routing, localNode, null));
        assertEquals(1, imc.availableShards().size());
        assertTrue(newShard.recoverFromStore());
        assertTrue("we should have flushed in IMC at least once but did: " + flushes.get(), flushes.get() >= 1);
        newShard.updateRoutingEntry(routing.moveToStarted());
    } finally {
        newShard.close("simon says", false);
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) AtomicReference(java.util.concurrent.atomic.AtomicReference) IndexSearcherWrapper(org.elasticsearch.index.shard.IndexSearcherWrapper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IndexSearcherWrapper (org.elasticsearch.index.shard.IndexSearcherWrapper)2 Path (java.nio.file.Path)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 Settings (org.elasticsearch.common.settings.Settings)1 IndexService (org.elasticsearch.index.IndexService)1 Searcher (org.elasticsearch.index.engine.Engine.Searcher)1 ContentPath (org.elasticsearch.index.mapper.ContentPath)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1 Store (org.elasticsearch.index.store.Store)1 RecoveryState (org.elasticsearch.indices.recovery.RecoveryState)1