Search in sources :

Example 1 with BackgroundIndexer

use of org.elasticsearch.test.BackgroundIndexer in project elasticsearch by elastic.

the class RecoveryWhileUnderLoadIT method testRecoverWhileUnderLoadWithReducedAllowedNodes.

public void testRecoverWhileUnderLoadWithReducedAllowedNodes() throws Exception {
    logger.info("--> creating test index ...");
    int numberOfShards = numberOfShards();
    assertAcked(prepareCreate("test", 2, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numberOfShards).put(SETTING_NUMBER_OF_REPLICAS, 1).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)));
    final int totalNumDocs = scaledRandomIntBetween(200, 10000);
    int waitFor = totalNumDocs / 10;
    int extraDocs = waitFor;
    try (BackgroundIndexer indexer = new BackgroundIndexer("test", "type", client(), extraDocs)) {
        logger.info("--> waiting for {} docs to be indexed ...", waitFor);
        waitForDocs(waitFor, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", waitFor);
        extraDocs = totalNumDocs / 10;
        waitFor += extraDocs;
        indexer.continueIndexing(extraDocs);
        logger.info("--> flushing the index ....");
        // now flush, just to make sure we have some data in the index, not just translog
        client().admin().indices().prepareFlush().execute().actionGet();
        logger.info("--> waiting for {} docs to be indexed ...", waitFor);
        waitForDocs(waitFor, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", waitFor);
        // now start more nodes, while we index
        extraDocs = totalNumDocs - waitFor;
        indexer.continueIndexing(extraDocs);
        logger.info("--> allow 4 nodes for index [test] ...");
        allowNodes("test", 4);
        logger.info("--> waiting for GREEN health status ...");
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForGreenStatus().setWaitForNoRelocatingShards(true));
        logger.info("--> waiting for {} docs to be indexed ...", totalNumDocs);
        waitForDocs(totalNumDocs, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", totalNumDocs);
        // now, shutdown nodes
        logger.info("--> allow 3 nodes for index [test] ...");
        allowNodes("test", 3);
        logger.info("--> waiting for relocations ...");
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForNoRelocatingShards(true));
        logger.info("--> allow 2 nodes for index [test] ...");
        allowNodes("test", 2);
        logger.info("--> waiting for relocations ...");
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForNoRelocatingShards(true));
        logger.info("--> allow 1 nodes for index [test] ...");
        allowNodes("test", 1);
        logger.info("--> waiting for relocations ...");
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForNoRelocatingShards(true));
        logger.info("--> marking and waiting for indexing threads to stop ...");
        indexer.stop();
        logger.info("--> indexing threads stopped");
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForNoRelocatingShards(true));
        logger.info("--> refreshing the index");
        refreshAndAssert();
        logger.info("--> verifying indexed content");
        iterateAssertCount(numberOfShards, 10, indexer.getIds());
    }
}
Also used : BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer)

Example 2 with BackgroundIndexer

use of org.elasticsearch.test.BackgroundIndexer in project elasticsearch by elastic.

the class RecoveryWhileUnderLoadIT method testRecoverWhileUnderLoadAllocateReplicasRelocatePrimariesTest.

public void testRecoverWhileUnderLoadAllocateReplicasRelocatePrimariesTest() throws Exception {
    logger.info("--> creating test index ...");
    int numberOfShards = numberOfShards();
    assertAcked(prepareCreate("test", 1, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numberOfShards).put(SETTING_NUMBER_OF_REPLICAS, 1).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)));
    final int totalNumDocs = scaledRandomIntBetween(200, 10000);
    int waitFor = totalNumDocs / 10;
    int extraDocs = waitFor;
    try (BackgroundIndexer indexer = new BackgroundIndexer("test", "type", client(), extraDocs)) {
        logger.info("--> waiting for {} docs to be indexed ...", waitFor);
        waitForDocs(waitFor, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", waitFor);
        extraDocs = totalNumDocs / 10;
        waitFor += extraDocs;
        indexer.continueIndexing(extraDocs);
        logger.info("--> flushing the index ....");
        // now flush, just to make sure we have some data in the index, not just translog
        client().admin().indices().prepareFlush().execute().actionGet();
        logger.info("--> waiting for {} docs to be indexed ...", waitFor);
        waitForDocs(waitFor, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", waitFor);
        extraDocs = totalNumDocs - waitFor;
        indexer.continueIndexing(extraDocs);
        logger.info("--> allow 4 nodes for index [test] ...");
        allowNodes("test", 4);
        logger.info("--> waiting for GREEN health status ...");
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForGreenStatus());
        logger.info("--> waiting for {} docs to be indexed ...", totalNumDocs);
        waitForDocs(totalNumDocs, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", totalNumDocs);
        logger.info("--> marking and waiting for indexing threads to stop ...");
        indexer.stop();
        logger.info("--> indexing threads stopped");
        logger.info("--> refreshing the index");
        refreshAndAssert();
        logger.info("--> verifying indexed content");
        iterateAssertCount(numberOfShards, 10, indexer.getIds());
    }
}
Also used : BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer)

Example 3 with BackgroundIndexer

use of org.elasticsearch.test.BackgroundIndexer in project elasticsearch by elastic.

the class RecoveryWhileUnderLoadIT method testRecoverWhileUnderLoadAllocateReplicasTest.

public void testRecoverWhileUnderLoadAllocateReplicasTest() throws Exception {
    logger.info("--> creating test index ...");
    int numberOfShards = numberOfShards();
    assertAcked(prepareCreate("test", 1, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numberOfShards).put(SETTING_NUMBER_OF_REPLICAS, 1).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)));
    final int totalNumDocs = scaledRandomIntBetween(200, 10000);
    int waitFor = totalNumDocs / 10;
    int extraDocs = waitFor;
    try (BackgroundIndexer indexer = new BackgroundIndexer("test", "type", client(), extraDocs)) {
        logger.info("--> waiting for {} docs to be indexed ...", waitFor);
        waitForDocs(waitFor, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", waitFor);
        extraDocs = totalNumDocs / 10;
        waitFor += extraDocs;
        indexer.continueIndexing(extraDocs);
        logger.info("--> flushing the index ....");
        // now flush, just to make sure we have some data in the index, not just translog
        client().admin().indices().prepareFlush().execute().actionGet();
        logger.info("--> waiting for {} docs to be indexed ...", waitFor);
        waitForDocs(waitFor, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", waitFor);
        extraDocs = totalNumDocs - waitFor;
        indexer.continueIndexing(extraDocs);
        logger.info("--> allow 2 nodes for index [test] ...");
        // now start another node, while we index
        allowNodes("test", 2);
        logger.info("--> waiting for GREEN health status ...");
        // make sure the cluster state is green, and all has been recovered
        assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setTimeout("5m").setWaitForGreenStatus());
        logger.info("--> waiting for {} docs to be indexed ...", totalNumDocs);
        waitForDocs(totalNumDocs, indexer);
        indexer.assertNoFailures();
        logger.info("--> {} docs indexed", totalNumDocs);
        logger.info("--> marking and waiting for indexing threads to stop ...");
        indexer.stop();
        logger.info("--> indexing threads stopped");
        logger.info("--> refreshing the index");
        refreshAndAssert();
        logger.info("--> verifying indexed content");
        iterateAssertCount(numberOfShards, 10, indexer.getIds());
    }
}
Also used : BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer)

Example 4 with BackgroundIndexer

use of org.elasticsearch.test.BackgroundIndexer in project elasticsearch by elastic.

the class RecoveryWhileUnderLoadIT method testRecoverWhileRelocating.

public void testRecoverWhileRelocating() throws Exception {
    final int numShards = between(2, 5);
    final int numReplicas = 0;
    logger.info("--> creating test index ...");
    int allowNodes = 2;
    assertAcked(prepareCreate("test", 3, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numShards).put(SETTING_NUMBER_OF_REPLICAS, numReplicas).put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.ASYNC)));
    final int numDocs = scaledRandomIntBetween(200, 9999);
    try (BackgroundIndexer indexer = new BackgroundIndexer("test", "type", client(), numDocs)) {
        for (int i = 0; i < numDocs; i += scaledRandomIntBetween(100, Math.min(1000, numDocs))) {
            indexer.assertNoFailures();
            logger.info("--> waiting for {} docs to be indexed ...", i);
            waitForDocs(i, indexer);
            logger.info("--> {} docs indexed", i);
            allowNodes = 2 / allowNodes;
            allowNodes("test", allowNodes);
            logger.info("--> waiting for GREEN health status ...");
            ensureGreen(TimeValue.timeValueMinutes(5));
        }
        logger.info("--> marking and waiting for indexing threads to stop ...");
        indexer.stop();
        logger.info("--> indexing threads stopped");
        logger.info("--> bump up number of replicas to 1 and allow all nodes to hold the index");
        allowNodes("test", 3);
        assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("number_of_replicas", 1)).get());
        ensureGreen(TimeValue.timeValueMinutes(5));
        logger.info("--> refreshing the index");
        refreshAndAssert();
        logger.info("--> verifying indexed content");
        iterateAssertCount(numShards, 10, indexer.getIds());
    }
}
Also used : BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer)

Example 5 with BackgroundIndexer

use of org.elasticsearch.test.BackgroundIndexer in project elasticsearch by elastic.

the class RelocationIT method testRelocationWhileIndexingRandom.

@TestLogging("org.elasticsearch.action.bulk:TRACE,org.elasticsearch.action.search:TRACE")
public void testRelocationWhileIndexingRandom() throws Exception {
    int numberOfRelocations = scaledRandomIntBetween(1, rarely() ? 10 : 4);
    int numberOfReplicas = randomBoolean() ? 0 : 1;
    int numberOfNodes = numberOfReplicas == 0 ? 2 : 3;
    logger.info("testRelocationWhileIndexingRandom(numRelocations={}, numberOfReplicas={}, numberOfNodes={})", numberOfRelocations, numberOfReplicas, numberOfNodes);
    String[] nodes = new String[numberOfNodes];
    logger.info("--> starting [node1] ...");
    nodes[0] = internalCluster().startNode();
    logger.info("--> creating test index ...");
    prepareCreate("test", Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", numberOfReplicas)).get();
    for (int i = 2; i <= numberOfNodes; i++) {
        logger.info("--> starting [node{}] ...", i);
        nodes[i - 1] = internalCluster().startNode();
        if (i != numberOfNodes) {
            ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(Integer.toString(i)).setWaitForGreenStatus().execute().actionGet();
            assertThat(healthResponse.isTimedOut(), equalTo(false));
        }
    }
    int numDocs = scaledRandomIntBetween(200, 2500);
    try (BackgroundIndexer indexer = new BackgroundIndexer("test", "type1", client(), numDocs)) {
        logger.info("--> waiting for {} docs to be indexed ...", numDocs);
        waitForDocs(numDocs, indexer);
        logger.info("--> {} docs indexed", numDocs);
        logger.info("--> starting relocations...");
        // if we have replicas shift those
        int nodeShiftBased = numberOfReplicas;
        for (int i = 0; i < numberOfRelocations; i++) {
            int fromNode = (i % 2);
            int toNode = fromNode == 0 ? 1 : 0;
            fromNode += nodeShiftBased;
            toNode += nodeShiftBased;
            numDocs = scaledRandomIntBetween(200, 1000);
            logger.debug("--> Allow indexer to index [{}] documents", numDocs);
            indexer.continueIndexing(numDocs);
            logger.info("--> START relocate the shard from {} to {}", nodes[fromNode], nodes[toNode]);
            client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test", 0, nodes[fromNode], nodes[toNode])).get();
            if (rarely()) {
                logger.debug("--> flushing");
                client().admin().indices().prepareFlush().get();
            }
            ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
            assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
            indexer.pauseIndexing();
            logger.info("--> DONE relocate the shard from {} to {}", fromNode, toNode);
        }
        logger.info("--> done relocations");
        logger.info("--> waiting for indexing threads to stop ...");
        indexer.stop();
        logger.info("--> indexing threads stopped");
        logger.info("--> refreshing the index");
        client().admin().indices().prepareRefresh("test").execute().actionGet();
        logger.info("--> searching the index");
        boolean ranOnce = false;
        for (int i = 0; i < 10; i++) {
            logger.info("--> START search test round {}", i + 1);
            SearchHits hits = client().prepareSearch("test").setQuery(matchAllQuery()).setSize((int) indexer.totalIndexedDocs()).storedFields().execute().actionGet().getHits();
            ranOnce = true;
            if (hits.getTotalHits() != indexer.totalIndexedDocs()) {
                int[] hitIds = new int[(int) indexer.totalIndexedDocs()];
                for (int hit = 0; hit < indexer.totalIndexedDocs(); hit++) {
                    hitIds[hit] = hit + 1;
                }
                IntHashSet set = IntHashSet.from(hitIds);
                for (SearchHit hit : hits.getHits()) {
                    int id = Integer.parseInt(hit.getId());
                    if (!set.remove(id)) {
                        logger.error("Extra id [{}]", id);
                    }
                }
                set.forEach((IntProcedure) value -> {
                    logger.error("Missing id [{}]", value);
                });
            }
            assertThat(hits.getTotalHits(), equalTo(indexer.totalIndexedDocs()));
            logger.info("--> DONE search test round {}", i + 1);
        }
        if (!ranOnce) {
            fail();
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Arrays(java.util.Arrays) TransportRequest(org.elasticsearch.transport.TransportRequest) Nullable(org.elasticsearch.common.Nullable) SearchHits(org.elasticsearch.search.SearchHits) Matchers.not(org.hamcrest.Matchers.not) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) SeqNoStats(org.elasticsearch.index.seqno.SeqNoStats) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) SearchResponse(org.elasticsearch.action.search.SearchResponse) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) SearchHit(org.elasticsearch.search.SearchHit) MockIndexEventListener(org.elasticsearch.test.MockIndexEventListener) Priority(org.elasticsearch.common.Priority) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Transport(org.elasticsearch.transport.Transport) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) Collection(java.util.Collection) RecoveryFileChunkRequest(org.elasticsearch.indices.recovery.RecoveryFileChunkRequest) ElasticsearchAssertions.assertHitCount(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount) Matchers.startsWith(org.hamcrest.Matchers.startsWith) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) FileVisitResult(java.nio.file.FileVisitResult) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL(org.elasticsearch.index.IndexSettings.INDEX_SEQ_NO_CHECKPOINT_SYNC_INTERVAL) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) IntProcedure(com.carrotsearch.hppc.procedures.IntProcedure) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexShardStats(org.elasticsearch.action.admin.indices.stats.IndexShardStats) ClusterService(org.elasticsearch.cluster.service.ClusterService) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) ArrayList(java.util.ArrayList) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SequenceNumbersService(org.elasticsearch.index.seqno.SequenceNumbersService) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) TimeValue(org.elasticsearch.common.unit.TimeValue) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) IndexShardState(org.elasticsearch.index.shard.IndexShardState) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) Client(org.elasticsearch.client.Client) IndexShard(org.elasticsearch.index.shard.IndexShard) IntHashSet(com.carrotsearch.hppc.IntHashSet) IndexFileNames(org.apache.lucene.index.IndexFileNames) Plugin(org.elasticsearch.plugins.Plugin) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) English(org.apache.lucene.util.English) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchAssertions.assertNoFailures(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) BackgroundIndexer(org.elasticsearch.test.BackgroundIndexer) SearchHit(org.elasticsearch.search.SearchHit) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) IntHashSet(com.carrotsearch.hppc.IntHashSet) SearchHits(org.elasticsearch.search.SearchHits) ElasticsearchAssertions.assertSearchHits(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging)

Aggregations

BackgroundIndexer (org.elasticsearch.test.BackgroundIndexer)5 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntProcedure (com.carrotsearch.hppc.procedures.IntProcedure)1 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 Semaphore (java.util.concurrent.Semaphore)1 TimeUnit (java.util.concurrent.TimeUnit)1 Stream (java.util.stream.Stream)1 IndexFileNames (org.apache.lucene.index.IndexFileNames)1