From a7da9866e842b30aa78127d889682318661b3639 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 16 Sep 2021 12:57:16 +0200 Subject: [PATCH] Adjust SearchableSnapshotsBlobStoreCacheIntegTests.testBlobStoreCache (#77758) (#77848) This test sometimes fails (#77753) when it tries to refresh the snapshot blob cache index while it wasn't created at all due to the test index being completely empty with 0 documents indexed. Having an empty index in this test does not make much sense because the index will contain no segments and therefore no segments file to cache in the system index. This commit adjusts the test to always index at least some docs. Backport of #77758 --- ...ableSnapshotsBlobStoreCacheIntegTests.java | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java index 79aacb39fba4a..bf1f5dfad8e13 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java @@ -114,7 +114,6 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) { return Settings.builder().put(super.nodeSettings(nodeOrdinal, otherSettings)).put(cacheSettings).build(); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/77753") public void testBlobStoreCache() throws Exception { final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); final boolean useSoftDeletes = randomBoolean(); @@ -122,16 +121,17 @@ public void testBlobStoreCache() throws Exception { final NumShards numberOfShards = getNumShards(indexName); - final int numberOfDocs = scaledRandomIntBetween(0, 20_000); - if (numberOfDocs > 0) { - final List indexRequestBuilders = new ArrayList<>(); - for (int i = numberOfDocs; i > 0; i--) { - XContentBuilder builder = XContentFactory.smileBuilder(); - builder.startObject().field("text", randomRealisticUnicodeOfCodepointLengthBetween(5, 50)).field("num", i).endObject(); - indexRequestBuilders.add(client().prepareIndex(indexName, SINGLE_MAPPING_NAME).setSource(builder)); - } - indexRandom(true, true, true, indexRequestBuilders); + final int numberOfDocs = scaledRandomIntBetween(10, 20_000); + logger.info("--> indexing [{}] documents in [{}]", numberOfDocs, indexName); + + final List indexRequestBuilders = new ArrayList<>(); + for (int i = numberOfDocs; i > 0; i--) { + XContentBuilder builder = XContentFactory.smileBuilder(); + builder.startObject().field("text", randomRealisticUnicodeOfCodepointLengthBetween(5, 50)).field("num", i).endObject(); + indexRequestBuilders.add(client().prepareIndex(indexName, SINGLE_MAPPING_NAME).setSource(builder)); } + indexRandom(true, true, true, indexRequestBuilders); + if (randomBoolean()) { logger.info("--> force-merging index before snapshotting"); final ForceMergeResponse forceMergeResponse = client().admin() @@ -200,20 +200,18 @@ public void testBlobStoreCache() throws Exception { } logger.info("--> verifying cached documents in system index [{}]", SNAPSHOT_BLOB_CACHE_INDEX); - if (numberOfDocs > 0) { - ensureYellow(SNAPSHOT_BLOB_CACHE_INDEX); - refreshSystemIndex(); + ensureYellow(SNAPSHOT_BLOB_CACHE_INDEX); + refreshSystemIndex(); - logger.info("--> verifying system index [{}] data tiers preference", SNAPSHOT_BLOB_CACHE_INDEX); - assertThat( - systemClient().admin() - .indices() - .prepareGetSettings(SNAPSHOT_BLOB_CACHE_INDEX) - .get() - .getSetting(SNAPSHOT_BLOB_CACHE_INDEX, DataTierAllocationDecider.INDEX_ROUTING_PREFER), - equalTo("data_content,data_hot") - ); - } + logger.info("--> verifying system index [{}] data tiers preference", SNAPSHOT_BLOB_CACHE_INDEX); + assertThat( + systemClient().admin() + .indices() + .prepareGetSettings(SNAPSHOT_BLOB_CACHE_INDEX) + .get() + .getSetting(SNAPSHOT_BLOB_CACHE_INDEX, DataTierAllocationDecider.INDEX_ROUTING_PREFER), + equalTo("data_content,data_hot") + ); final long numberOfCachedBlobs = systemClient().prepareSearch(SNAPSHOT_BLOB_CACHE_INDEX) .setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN) @@ -267,9 +265,7 @@ public void testBlobStoreCache() throws Exception { assertHitCount(client().prepareSearch(restoredAgainIndex).setSize(0).setTrackTotalHits(true).get(), numberOfDocs); logger.info("--> verifying that no extra cached blobs were indexed [{}]", SNAPSHOT_BLOB_CACHE_INDEX); - if (numberOfDocs > 0) { - refreshSystemIndex(); - } + refreshSystemIndex(); assertHitCount( systemClient().prepareSearch(SNAPSHOT_BLOB_CACHE_INDEX).setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN).setSize(0).get(), numberOfCachedBlobs