Skip to content

Commit 35d2d0b

Browse files
tlrxelasticmachine
andauthored
Adjust SearchableSnapshotsBlobStoreCacheIntegTests.testBlobStoreCache (#77758) (#77844)
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 Co-authored-by: Elastic Machine <[email protected]>
1 parent 79d65f6 commit 35d2d0b

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,24 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
114114
return Settings.builder().put(super.nodeSettings(nodeOrdinal, otherSettings)).put(cacheSettings).build();
115115
}
116116

117-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/77753")
118117
public void testBlobStoreCache() throws Exception {
119118
final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
120119
final boolean useSoftDeletes = randomBoolean();
121120
createIndex(indexName, Settings.builder().put(INDEX_SOFT_DELETES_SETTING.getKey(), useSoftDeletes).build());
122121

123122
final NumShards numberOfShards = getNumShards(indexName);
124123

125-
final int numberOfDocs = scaledRandomIntBetween(0, 20_000);
126-
if (numberOfDocs > 0) {
127-
final List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
128-
for (int i = numberOfDocs; i > 0; i--) {
129-
XContentBuilder builder = XContentFactory.smileBuilder();
130-
builder.startObject().field("text", randomRealisticUnicodeOfCodepointLengthBetween(5, 50)).field("num", i).endObject();
131-
indexRequestBuilders.add(client().prepareIndex(indexName, SINGLE_MAPPING_NAME).setSource(builder));
132-
}
133-
indexRandom(true, true, true, indexRequestBuilders);
124+
final int numberOfDocs = scaledRandomIntBetween(10, 20_000);
125+
logger.info("--> indexing [{}] documents in [{}]", numberOfDocs, indexName);
126+
127+
final List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
128+
for (int i = numberOfDocs; i > 0; i--) {
129+
XContentBuilder builder = XContentFactory.smileBuilder();
130+
builder.startObject().field("text", randomRealisticUnicodeOfCodepointLengthBetween(5, 50)).field("num", i).endObject();
131+
indexRequestBuilders.add(client().prepareIndex(indexName, SINGLE_MAPPING_NAME).setSource(builder));
134132
}
133+
indexRandom(true, true, true, indexRequestBuilders);
134+
135135
if (randomBoolean()) {
136136
logger.info("--> force-merging index before snapshotting");
137137
final ForceMergeResponse forceMergeResponse = client().admin()
@@ -200,20 +200,18 @@ public void testBlobStoreCache() throws Exception {
200200
}
201201

202202
logger.info("--> verifying cached documents in system index [{}]", SNAPSHOT_BLOB_CACHE_INDEX);
203-
if (numberOfDocs > 0) {
204-
ensureYellow(SNAPSHOT_BLOB_CACHE_INDEX);
205-
refreshSystemIndex();
203+
ensureYellow(SNAPSHOT_BLOB_CACHE_INDEX);
204+
refreshSystemIndex();
206205

207-
logger.info("--> verifying system index [{}] data tiers preference", SNAPSHOT_BLOB_CACHE_INDEX);
208-
assertThat(
209-
systemClient().admin()
210-
.indices()
211-
.prepareGetSettings(SNAPSHOT_BLOB_CACHE_INDEX)
212-
.get()
213-
.getSetting(SNAPSHOT_BLOB_CACHE_INDEX, DataTierAllocationDecider.INDEX_ROUTING_PREFER),
214-
equalTo("data_content,data_hot")
215-
);
216-
}
206+
logger.info("--> verifying system index [{}] data tiers preference", SNAPSHOT_BLOB_CACHE_INDEX);
207+
assertThat(
208+
systemClient().admin()
209+
.indices()
210+
.prepareGetSettings(SNAPSHOT_BLOB_CACHE_INDEX)
211+
.get()
212+
.getSetting(SNAPSHOT_BLOB_CACHE_INDEX, DataTierAllocationDecider.INDEX_ROUTING_PREFER),
213+
equalTo("data_content,data_hot")
214+
);
217215

218216
final long numberOfCachedBlobs = systemClient().prepareSearch(SNAPSHOT_BLOB_CACHE_INDEX)
219217
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN)
@@ -267,9 +265,7 @@ public void testBlobStoreCache() throws Exception {
267265
assertHitCount(client().prepareSearch(restoredAgainIndex).setSize(0).setTrackTotalHits(true).get(), numberOfDocs);
268266

269267
logger.info("--> verifying that no extra cached blobs were indexed [{}]", SNAPSHOT_BLOB_CACHE_INDEX);
270-
if (numberOfDocs > 0) {
271-
refreshSystemIndex();
272-
}
268+
refreshSystemIndex();
273269
assertHitCount(
274270
systemClient().prepareSearch(SNAPSHOT_BLOB_CACHE_INDEX).setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN).setSize(0).get(),
275271
numberOfCachedBlobs

0 commit comments

Comments
 (0)