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").setMapping("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);
}
use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.
the class IndicesRequestCacheIT method testQueryRewrite.
public void testQueryRewrite() throws Exception {
Client client = client();
assertAcked(client.admin().indices().prepareCreate("index").setMapping("s", "type=date").setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 5).put("index.number_of_routing_shards", 5).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)).get());
indexRandom(true, client.prepareIndex("index").setId("1").setRouting("1").setSource("s", "2016-03-19"), client.prepareIndex("index").setId("2").setRouting("1").setSource("s", "2016-03-20"), client.prepareIndex("index").setId("3").setRouting("1").setSource("s", "2016-03-21"), client.prepareIndex("index").setId("4").setRouting("2").setSource("s", "2016-03-22"), client.prepareIndex("index").setId("5").setRouting("2").setSource("s", "2016-03-23"), client.prepareIndex("index").setId("6").setRouting("2").setSource("s", "2016-03-24"), client.prepareIndex("index").setId("7").setRouting("3").setSource("s", "2016-03-25"), client.prepareIndex("index").setId("8").setRouting("3").setSource("s", "2016-03-26"), client.prepareIndex("index").setId("9").setRouting("3").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-25")).addAggregation(new GlobalAggregationBuilder("global")).get();
OpenSearchAssertions.assertAllSuccessful(r1);
assertThat(r1.getHits().getTotalHits().value, equalTo(7L));
assertCacheState(client, "index", 0, 5);
final SearchResponse r2 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-20").lte("2016-03-26")).addAggregation(new GlobalAggregationBuilder("global")).get();
OpenSearchAssertions.assertAllSuccessful(r2);
assertThat(r2.getHits().getTotalHits().value, equalTo(7L));
assertCacheState(client, "index", 3, 7);
final SearchResponse r3 = client.prepareSearch("index").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(0).setQuery(QueryBuilders.rangeQuery("s").gte("2016-03-21").lte("2016-03-27")).addAggregation(new GlobalAggregationBuilder("global")).get();
OpenSearchAssertions.assertAllSuccessful(r3);
assertThat(r3.getHits().getTotalHits().value, equalTo(7L));
assertCacheState(client, "index", 6, 9);
}
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().startClusterManagerOnlyNode();
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));
}
use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.
the class OpenSearchMockAPIBasedRepositoryIntegTestCase method testRequestStats.
public void testRequestStats() throws Exception {
final String repository = createRepository(randomName());
final String index = "index-no-merges";
createIndex(index, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build());
final long nbDocs = randomLongBetween(10_000L, 20_000L);
try (BackgroundIndexer indexer = new BackgroundIndexer(index, "_doc", client(), (int) nbDocs)) {
waitForDocs(nbDocs, indexer);
}
flushAndRefresh(index);
ForceMergeResponse forceMerge = client().admin().indices().prepareForceMerge(index).setFlush(true).setMaxNumSegments(1).get();
assertThat(forceMerge.getSuccessfulShards(), equalTo(1));
assertHitCount(client().prepareSearch(index).setSize(0).setTrackTotalHits(true).get(), nbDocs);
final String snapshot = "snapshot";
assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repository, snapshot).setWaitForCompletion(true).setIndices(index));
assertAcked(client().admin().indices().prepareDelete(index));
assertSuccessfulRestore(client().admin().cluster().prepareRestoreSnapshot(repository, snapshot).setWaitForCompletion(true));
ensureGreen(index);
assertHitCount(client().prepareSearch(index).setSize(0).setTrackTotalHits(true).get(), nbDocs);
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repository, snapshot).get());
final RepositoryStats repositoryStats = StreamSupport.stream(internalCluster().getInstances(RepositoriesService.class).spliterator(), false).map(repositoriesService -> {
try {
return repositoriesService.repository(repository);
} catch (RepositoryMissingException e) {
return null;
}
}).filter(Objects::nonNull).map(Repository::stats).reduce(RepositoryStats::merge).get();
Map<String, Long> sdkRequestCounts = repositoryStats.requestCounts;
final Map<String, Long> mockCalls = getMockRequestCounts();
String assertionErrorMsg = String.format("SDK sent [%s] calls and handler measured [%s] calls", sdkRequestCounts, mockCalls);
assertEquals(assertionErrorMsg, mockCalls, sdkRequestCounts);
}
use of org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse in project OpenSearch by opensearch-project.
the class OpenSearchMockAPIBasedRepositoryIntegTestCase method testSnapshotWithLargeSegmentFiles.
/**
* Test the snapshot and restore of an index which has large segments files.
*/
public void testSnapshotWithLargeSegmentFiles() throws Exception {
final String repository = createRepository(randomName());
final String index = "index-no-merges";
createIndex(index, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build());
final long nbDocs = randomLongBetween(10_000L, 20_000L);
try (BackgroundIndexer indexer = new BackgroundIndexer(index, "_doc", client(), (int) nbDocs)) {
waitForDocs(nbDocs, indexer);
}
flushAndRefresh(index);
ForceMergeResponse forceMerge = client().admin().indices().prepareForceMerge(index).setFlush(true).setMaxNumSegments(1).get();
assertThat(forceMerge.getSuccessfulShards(), equalTo(1));
assertHitCount(client().prepareSearch(index).setSize(0).setTrackTotalHits(true).get(), nbDocs);
final String snapshot = "snapshot";
assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repository, snapshot).setWaitForCompletion(true).setIndices(index));
assertAcked(client().admin().indices().prepareDelete(index));
assertSuccessfulRestore(client().admin().cluster().prepareRestoreSnapshot(repository, snapshot).setWaitForCompletion(true));
ensureGreen(index);
assertHitCount(client().prepareSearch(index).setSize(0).setTrackTotalHits(true).get(), nbDocs);
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repository, snapshot).get());
}
Aggregations