Search in sources :

Example 1 with ForceMergeResponse

use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.

the class BlobStoreIncrementalityIT method testForceMergeCausesFullSnapshot.

public void testForceMergeCausesFullSnapshot() throws Exception {
    internalCluster().startMasterOnlyNode();
    internalCluster().ensureAtLeastNumDataNodes(2);
    final String indexName = "test-index";
    createIndex(indexName, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).build());
    ensureGreen(indexName);
    logger.info("--> adding some documents to test index and flush in between to get at least two segments");
    for (int j = 0; j < 2; j++) {
        final BulkRequest bulkRequest = new BulkRequest();
        for (int i = 0; i < scaledRandomIntBetween(1, 100); ++i) {
            bulkRequest.add(new IndexRequest(indexName).source("foo" + j, "bar" + i));
        }
        client().bulk(bulkRequest).get();
        flushAndRefresh(indexName);
    }
    final IndexStats indexStats = client().admin().indices().prepareStats(indexName).get().getIndex(indexName);
    assertThat(indexStats.getIndexShards().get(0).getPrimary().getSegments().getCount(), greaterThan(1L));
    final String snapshot1 = "snap-1";
    final String repo = "test-repo";
    createRepository(repo, "fs");
    logger.info("--> creating snapshot 1");
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot1).setIndices(indexName).setWaitForCompletion(true).get();
    logger.info("--> force merging down to a single segment");
    final ForceMergeResponse forceMergeResponse = client().admin().indices().prepareForceMerge(indexName).setMaxNumSegments(1).setFlush(true).get();
    assertThat(forceMergeResponse.getFailedShards(), is(0));
    final String snapshot2 = "snap-2";
    logger.info("--> creating snapshot 2");
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot2).setIndices(indexName).setWaitForCompletion(true).get();
    logger.info("--> asserting that the two snapshots refer to different files in the repository");
    final SnapshotStats secondSnapshotShardStatus = getStats(repo, snapshot2).getIndices().get(indexName).getShards().get(0).getStats();
    assertThat(secondSnapshotShardStatus.getIncrementalFileCount(), greaterThan(0));
}
Also used : ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) SnapshotStats(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats) BulkRequest(org.opensearch.action.bulk.BulkRequest) IndexRequest(org.opensearch.action.index.IndexRequest) IndexStats(org.opensearch.action.admin.indices.stats.IndexStats)

Example 2 with ForceMergeResponse

use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.

the class CompletionSuggestSearchIT method testPrunedSegments.

// see #3555
public void testPrunedSegments() throws IOException {
    createIndexAndMappingAndSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).build(), completionMappingBuilder);
    client().prepareIndex(INDEX).setId("1").setSource(jsonBuilder().startObject().startObject(FIELD).startArray("input").value("The Beatles").endArray().endObject().endObject()).get();
    client().prepareIndex(INDEX).setId("2").setSource(jsonBuilder().startObject().field("somefield", "somevalue").endObject()).get();
    ForceMergeResponse actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).get();
    assertAllSuccessful(actionGet);
    refresh();
    // update the first one and then merge.. the target segment will have no value in FIELD
    client().prepareIndex(INDEX).setId("1").setSource(jsonBuilder().startObject().field("somefield", "somevalue").endObject()).get();
    actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).get();
    assertAllSuccessful(actionGet);
    refresh();
    assertSuggestions("b");
    assertThat(2L, equalTo(client().prepareSearch(INDEX).setSize(0).get().getHits().getTotalHits().value));
    for (IndexShardSegments seg : client().admin().indices().prepareSegments().get().getIndices().get(INDEX)) {
        ShardSegments[] shards = seg.getShards();
        for (ShardSegments shardSegments : shards) {
            assertThat(shardSegments.getSegments().size(), equalTo(1));
        }
    }
}
Also used : ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) ShardSegments(org.opensearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments)

Example 3 with ForceMergeResponse

use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.

the class IndexingMemoryControllerIT method testDeletesAloneCanTriggerRefresh.

// #10312
public void testDeletesAloneCanTriggerRefresh() throws Exception {
    IndexService indexService = createIndex("index", Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.refresh_interval", -1).build());
    IndexShard shard = indexService.getShard(0);
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("index").setId(Integer.toString(i)).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);
    final RefreshStats refreshStats = shard.refreshStats();
    for (int i = 0; i < 100; i++) {
        client().prepareDelete("index", Integer.toString(i)).get();
    }
    // need to assert busily as IndexingMemoryController refreshes in background
    assertBusy(() -> assertThat(shard.refreshStats().getTotal(), greaterThan(refreshStats.getTotal() + 1)));
}
Also used : ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) IndexService(org.opensearch.index.IndexService) RefreshStats(org.opensearch.index.refresh.RefreshStats) IndexShard(org.opensearch.index.shard.IndexShard)

Example 4 with ForceMergeResponse

use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.

the class IndicesRequestCacheIT method testQueryRewriteDates.

public void testQueryRewriteDates() throws Exception {
    Client client = client();
    assertAcked(client.admin().indices().prepareCreate("index").addMapping("type", "d", "type=date").setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)).get());
    indexRandom(true, client.prepareIndex("index").setId("1").setSource("d", "2014-01-01T00:00:00"), client.prepareIndex("index").setId("2").setSource("d", "2014-02-01T00:00:00"), client.prepareIndex("index").setId("3").setSource("d", "2014-03-01T00:00:00"), client.prepareIndex("index").setId("4").setSource("d", "2014-04-01T00:00:00"), client.prepareIndex("index").setId("5").setSource("d", "2014-05-01T00:00:00"), client.prepareIndex("index").setId("6").setSource("d", "2014-06-01T00:00:00"), client.prepareIndex("index").setId("7").setSource("d", "2014-07-01T00:00:00"), client.prepareIndex("index").setId("8").setSource("d", "2014-08-01T00:00:00"), client.prepareIndex("index").setId("9").setSource("d", "2014-09-01T00:00:00"));
    ensureSearchable("index");
    assertCacheState(client, "index", 0, 0);
    // Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
    ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge("index").setFlush(true).get();
    OpenSearchAssertions.assertAllSuccessful(forceMergeResponse);
    refresh();
    ensureSearchable("index");
    assertCacheState(client, "index", 0, 0);
    final SearchResponse r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("d").gte("2013-01-01T00:00:00").lte("now")).addAggregation(new GlobalAggregationBuilder("global")).get();
    OpenSearchAssertions.assertAllSuccessful(r1);
    assertThat(r1.getHits().getTotalHits().value, equalTo(9L));
    assertCacheState(client, "index", 0, 1);
    final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("d").gte("2013-01-01T00:00:00").lte("now")).addAggregation(new GlobalAggregationBuilder("global")).get();
    OpenSearchAssertions.assertAllSuccessful(r2);
    assertThat(r2.getHits().getTotalHits().value, equalTo(9L));
    assertCacheState(client, "index", 1, 1);
    final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("d").gte("2013-01-01T00:00:00").lte("now")).addAggregation(new GlobalAggregationBuilder("global")).get();
    OpenSearchAssertions.assertAllSuccessful(r3);
    assertThat(r3.getHits().getTotalHits().value, equalTo(9L));
    assertCacheState(client, "index", 2, 1);
}
Also used : ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) Client(org.opensearch.client.Client) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse) GlobalAggregationBuilder(org.opensearch.search.aggregations.bucket.global.GlobalAggregationBuilder)

Example 5 with ForceMergeResponse

use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.

the class IndicesRequestCacheIT method testQueryRewriteMissingValues.

public void testQueryRewriteMissingValues() throws Exception {
    Client client = client();
    assertAcked(client.admin().indices().prepareCreate("index").addMapping("type", "s", "type=date").setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)).get());
    indexRandom(true, client.prepareIndex("index").setId("1").setSource("s", "2016-03-19"), client.prepareIndex("index").setId("2").setSource("s", "2016-03-20"), client.prepareIndex("index").setId("3").setSource("s", "2016-03-21"), client.prepareIndex("index").setId("4").setSource("s", "2016-03-22"), client.prepareIndex("index").setId("5").setSource("s", "2016-03-23"), client.prepareIndex("index").setId("6").setSource("s", "2016-03-24"), client.prepareIndex("index").setId("7").setSource("other", "value"), client.prepareIndex("index").setId("8").setSource("s", "2016-03-26"), client.prepareIndex("index").setId("9").setSource("s", "2016-03-27"));
    ensureSearchable("index");
    assertCacheState(client, "index", 0, 0);
    // Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
    ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge("index").setFlush(true).get();
    OpenSearchAssertions.assertAllSuccessful(forceMergeResponse);
    refresh();
    ensureSearchable("index");
    assertCacheState(client, "index", 0, 0);
    final SearchResponse r1 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-28")).get();
    OpenSearchAssertions.assertAllSuccessful(r1);
    assertThat(r1.getHits().getTotalHits().value, equalTo(8L));
    assertCacheState(client, "index", 0, 1);
    final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-28")).get();
    OpenSearchAssertions.assertAllSuccessful(r2);
    assertThat(r2.getHits().getTotalHits().value, equalTo(8L));
    assertCacheState(client, "index", 1, 1);
    final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-19").lte("2016-03-28")).get();
    OpenSearchAssertions.assertAllSuccessful(r3);
    assertThat(r3.getHits().getTotalHits().value, equalTo(8L));
    assertCacheState(client, "index", 2, 1);
}
Also used : ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) Client(org.opensearch.client.Client) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

ForceMergeResponse (org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse)14 SearchResponse (org.opensearch.action.search.SearchResponse)7 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)7 Client (org.opensearch.client.Client)6 Settings (org.opensearch.common.settings.Settings)4 ZonedDateTime (java.time.ZonedDateTime)2 GetResponse (org.opensearch.action.get.GetResponse)2 IndexResponse (org.opensearch.action.index.IndexResponse)2 GlobalAggregationBuilder (org.opensearch.search.aggregations.bucket.global.GlobalAggregationBuilder)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1