Search in sources :

Example 6 with ForceMergeResponse

use of org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse in project elasticsearch by elastic.

the class IndexingMemoryControllerTests method testDeletesAloneCanTriggerRefresh.

// #10312
public void testDeletesAloneCanTriggerRefresh() throws Exception {
    createIndex("index", Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.refresh_interval", -1).build());
    ensureGreen();
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService indexService = indicesService.indexService(resolveIndex("index"));
    IndexShard shard = indexService.getShardOrNull(0);
    assertNotNull(shard);
    for (int i = 0; i < 100; i++) {
        String id = Integer.toString(i);
        client().prepareIndex("index", "type", id).setSource("field", "value").get();
    }
    // Force merge so we know all merges are done before we start deleting:
    ForceMergeResponse r = client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet();
    assertNoFailures(r);
    // Make a shell of an IMC to check up on indexing buffer usage:
    Settings settings = Settings.builder().put("indices.memory.index_buffer_size", "1kb").build();
    // TODO: would be cleaner if I could pass this 1kb setting to the single node this test created....
    IndexingMemoryController imc = new IndexingMemoryController(settings, null, null) {

        @Override
        protected List<IndexShard> availableShards() {
            return Collections.singletonList(shard);
        }

        @Override
        protected long getIndexBufferRAMBytesUsed(IndexShard shard) {
            return shard.getIndexBufferRAMBytesUsed();
        }

        @Override
        protected void writeIndexingBufferAsync(IndexShard shard) {
            // just do it sync'd for this test
            shard.writeIndexingBuffer();
        }

        @Override
        protected Cancellable scheduleTask(ThreadPool threadPool) {
            return null;
        }
    };
    for (int i = 0; i < 100; i++) {
        String id = Integer.toString(i);
        client().prepareDelete("index", "type", id).get();
    }
    final long indexingBufferBytes1 = shard.getIndexBufferRAMBytesUsed();
    imc.forceCheck();
    // We must assertBusy because the writeIndexingBufferAsync is done in background (REFRESH) thread pool:
    assertBusy(new Runnable() {

        @Override
        public void run() {
            try (Engine.Searcher s2 = shard.acquireSearcher("index")) {
                // 100 buffered deletes will easily exceed our 1 KB indexing buffer so it should trigger a write:
                final long indexingBufferBytes2 = shard.getIndexBufferRAMBytesUsed();
                assertTrue(indexingBufferBytes2 < indexingBufferBytes1);
            }
        }
    });
}
Also used : ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

ForceMergeResponse (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)6 ForceMergeRequest (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest)2 Settings (org.elasticsearch.common.settings.Settings)2 FutureActionListener (io.crate.action.FutureActionListener)1 IOException (java.io.IOException)1 ClearIndicesCacheResponse (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse)1 FlushResponse (org.elasticsearch.action.admin.indices.flush.FlushResponse)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 IndexShardSegments (org.elasticsearch.action.admin.indices.segments.IndexShardSegments)1 ShardSegments (org.elasticsearch.action.admin.indices.segments.ShardSegments)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 GetResponse (org.elasticsearch.action.get.GetResponse)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 IndexService (org.elasticsearch.index.IndexService)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1