Search in sources :

Example 1 with ByteSizeValue

use of org.opensearch.common.unit.ByteSizeValue in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testBulkProcessorWaitOnClose.

public void testBulkProcessorWaitOnClose() throws Exception {
    BulkProcessorTestListener listener = new BulkProcessorTestListener();
    int numDocs = randomIntBetween(10, 100);
    BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(randomIntBetween(1, 10), RandomPicks.randomFrom(random(), ByteSizeUnit.values()))).build();
    MultiGetRequest multiGetRequest = indexDocs(processor, numDocs);
    assertThat(processor.awaitClose(1, TimeUnit.MINUTES), is(true));
    if (randomBoolean()) {
        // check if we can call it multiple times
        if (randomBoolean()) {
            assertThat(processor.awaitClose(1, TimeUnit.MINUTES), is(true));
        } else {
            processor.close();
        }
    }
    assertThat(listener.beforeCounts.get(), greaterThanOrEqualTo(1));
    assertThat(listener.afterCounts.get(), greaterThanOrEqualTo(1));
    for (Throwable bulkFailure : listener.bulkFailures) {
        logger.error("bulk failure", bulkFailure);
    }
    assertThat(listener.bulkFailures.size(), equalTo(0));
    assertResponseItems(listener.bulkItems, numDocs);
    assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
}
Also used : BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 2 with ByteSizeValue

use of org.opensearch.common.unit.ByteSizeValue in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testThatBulkProcessorCountIsCorrect.

public void testThatBulkProcessorCountIsCorrect() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);
    int numDocs = randomIntBetween(10, 100);
    try (BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).build()) {
        MultiGetRequest multiGetRequest = indexDocs(processor, numDocs);
        latch.await();
        assertThat(listener.beforeCounts.get(), equalTo(1));
        assertThat(listener.afterCounts.get(), equalTo(1));
        assertThat(listener.bulkFailures.size(), equalTo(0));
        assertResponseItems(listener.bulkItems, numDocs);
        assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
    }
}
Also used : BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) CountDownLatch(java.util.concurrent.CountDownLatch) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 3 with ByteSizeValue

use of org.opensearch.common.unit.ByteSizeValue in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testGlobalParametersAndBulkProcessor.

public void testGlobalParametersAndBulkProcessor() throws Exception {
    createIndexWithMultipleShards("test");
    createFieldAddingPipleine("pipeline_id", "fieldNameXYZ", "valueXYZ");
    int numDocs = randomIntBetween(10, 10);
    {
        final CountDownLatch latch = new CountDownLatch(1);
        BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);
        try (BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).setGlobalIndex("test").setGlobalRouting("routing").setGlobalPipeline("pipeline_id").build()) {
            indexDocs(processor, numDocs, null, "test", "pipeline_id");
            latch.await();
            assertThat(listener.beforeCounts.get(), equalTo(1));
            assertThat(listener.afterCounts.get(), equalTo(1));
            assertThat(listener.bulkFailures.size(), equalTo(0));
            assertResponseItems(listener.bulkItems, numDocs);
            Iterable<SearchHit> hits = searchAll(new SearchRequest("test").routing("routing"));
            assertThat(hits, everyItem(hasProperty(fieldFromSource("fieldNameXYZ"), equalTo("valueXYZ"))));
            assertThat(hits, containsInAnyOrder(expectedIds(numDocs)));
        }
    }
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with ByteSizeValue

use of org.opensearch.common.unit.ByteSizeValue in project OpenSearch by opensearch-project.

the class BulkProcessorIT method testBulkProcessorFlush.

public void testBulkProcessorFlush() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);
    int numDocs = randomIntBetween(10, 100);
    try (BulkProcessor processor = initBulkProcessorBuilder(listener).setConcurrentRequests(randomIntBetween(0, 10)).setBulkActions(numDocs + randomIntBetween(1, 100)).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).build()) {
        MultiGetRequest multiGetRequest = indexDocs(processor, numDocs);
        assertThat(latch.await(randomInt(500), TimeUnit.MILLISECONDS), equalTo(false));
        // we really need an explicit flush as none of the bulk thresholds was reached
        processor.flush();
        latch.await();
        assertThat(listener.beforeCounts.get(), equalTo(1));
        assertThat(listener.afterCounts.get(), equalTo(1));
        assertThat(listener.bulkFailures.size(), equalTo(0));
        assertResponseItems(listener.bulkItems, numDocs);
        assertMultiGetResponse(highLevelClient().mget(multiGetRequest, RequestOptions.DEFAULT), numDocs);
    }
}
Also used : BulkProcessor(org.opensearch.action.bulk.BulkProcessor) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) CountDownLatch(java.util.concurrent.CountDownLatch) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 5 with ByteSizeValue

use of org.opensearch.common.unit.ByteSizeValue in project OpenSearch by opensearch-project.

the class IndicesClientIT method testRollover.

public void testRollover() throws IOException {
    highLevelClient().indices().create(new CreateIndexRequest("test").alias(new Alias("alias")), RequestOptions.DEFAULT);
    RolloverRequest rolloverRequest = new RolloverRequest("alias", "test_new");
    rolloverRequest.addMaxIndexDocsCondition(1);
    {
        RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover, highLevelClient().indices()::rolloverAsync);
        assertFalse(rolloverResponse.isRolledOver());
        assertFalse(rolloverResponse.isDryRun());
        Map<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus();
        assertEquals(1, conditionStatus.size());
        assertFalse(conditionStatus.get("[max_docs: 1]"));
        assertEquals("test", rolloverResponse.getOldIndex());
        assertEquals("test_new", rolloverResponse.getNewIndex());
    }
    highLevelClient().index(new IndexRequest("test").id("1").source("field", "value"), RequestOptions.DEFAULT);
    highLevelClient().index(new IndexRequest("test").id("2").source("field", "value").setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL), RequestOptions.DEFAULT);
    // without the refresh the rollover may not happen as the number of docs seen may be off
    {
        rolloverRequest.addMaxIndexAgeCondition(new TimeValue(1));
        rolloverRequest.dryRun(true);
        RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover, highLevelClient().indices()::rolloverAsync);
        assertFalse(rolloverResponse.isRolledOver());
        assertTrue(rolloverResponse.isDryRun());
        Map<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus();
        assertEquals(2, conditionStatus.size());
        assertTrue(conditionStatus.get("[max_docs: 1]"));
        assertTrue(conditionStatus.get("[max_age: 1ms]"));
        assertEquals("test", rolloverResponse.getOldIndex());
        assertEquals("test_new", rolloverResponse.getNewIndex());
    }
    {
        String mappings = "{\"properties\":{\"field2\":{\"type\":\"keyword\"}}}";
        rolloverRequest.getCreateIndexRequest().mapping(mappings, XContentType.JSON);
        rolloverRequest.dryRun(false);
        rolloverRequest.addMaxIndexSizeCondition(new ByteSizeValue(1, ByteSizeUnit.MB));
        RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover, highLevelClient().indices()::rolloverAsync);
        assertTrue(rolloverResponse.isRolledOver());
        assertFalse(rolloverResponse.isDryRun());
        Map<String, Boolean> conditionStatus = rolloverResponse.getConditionStatus();
        assertEquals(3, conditionStatus.size());
        assertTrue(conditionStatus.get("[max_docs: 1]"));
        assertTrue(conditionStatus.get("[max_age: 1ms]"));
        assertFalse(conditionStatus.get("[max_size: 1mb]"));
        assertEquals("test", rolloverResponse.getOldIndex());
        assertEquals("test_new", rolloverResponse.getNewIndex());
    }
}
Also used : RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) Alias(org.opensearch.action.admin.indices.alias.Alias) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) RolloverResponse(org.opensearch.client.indices.rollover.RolloverResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) IndexRequest(org.opensearch.action.index.IndexRequest) Map(java.util.Map) HashMap(java.util.HashMap) TimeValue(org.opensearch.common.unit.TimeValue)

Aggregations

ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)118 Settings (org.opensearch.common.settings.Settings)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 TimeValue (org.opensearch.common.unit.TimeValue)19 ArrayList (java.util.ArrayList)16 Matchers.containsString (org.hamcrest.Matchers.containsString)15 List (java.util.List)13 IOException (java.io.IOException)12 IndexRequest (org.opensearch.action.index.IndexRequest)12 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)12 Map (java.util.Map)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 IndexSettings (org.opensearch.index.IndexSettings)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 XContentType (org.opensearch.common.xcontent.XContentType)10 HashMap (java.util.HashMap)8 BytesReference (org.opensearch.common.bytes.BytesReference)8 ByteSizeUnit (org.opensearch.common.unit.ByteSizeUnit)8 ByteBuffer (java.nio.ByteBuffer)7 Collections (java.util.Collections)7