Skip to content

Commit 26fa9d3

Browse files
authored
Exclude partially cached .cfs file from SearchableSnapshotDirectoryStatsTests (#70006) (#70018)
Since #69861 CFS files read from FrozenIndexInput create dedicated frozen shared cache files when they are sliced. This does not play well with some tests that use the randomReadAndSlice to read files: this method can create overlapping slice/clone reads operations which makes it difficult to assert anything about CFS files with partial cache. This commit prevent the tests to generate a .cfs file name when the partial cache is randomly picked up. As a follow up we should rework those test to make them more realistic with the new behavior. Closes #70000
1 parent e45db43 commit 26fa9d3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

test/framework/src/main/java/org/elasticsearch/common/lucene/store/ESIndexInputTestCase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ protected byte[] randomReadAndSlice(IndexInput indexInput, int length) throws IO
7272
case 3:
7373
// Read using slice
7474
len = randomIntBetween(1, length - readPos);
75-
IndexInput slice = indexInput.slice(randomAlphaOfLength(10) + randomFileExtension(), readPos, len);
75+
final String sliceExtension = randomValueOtherThan(".cfs", ESIndexInputTestCase::randomFileExtension);
76+
IndexInput slice = indexInput.slice(randomAlphaOfLength(10) + sliceExtension, readPos, len);
7677
temp = randomReadAndSlice(slice, len);
7778
// assert that position in the original input didn't change
7879
assertEquals(readPos, indexInput.getFilePointer());
@@ -121,7 +122,8 @@ protected void doRun() throws Exception {
121122
clone = indexInput.clone();
122123
} else {
123124
final int sliceEnd = between(readEnd, length);
124-
clone = indexInput.slice("slice" + randomAlphaOfLength(10) + randomFileExtension(), 0L, sliceEnd);
125+
final String sliceExtension = randomValueOtherThan(".cfs", ESIndexInputTestCase::randomFileExtension);
126+
clone = indexInput.slice("slice" + randomAlphaOfLength(10) + sliceExtension, 0L, sliceEnd);
125127
}
126128
startLatch.countDown();
127129
startLatch.await();

x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryStatsTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.common.TriConsumer;
2020
import org.elasticsearch.common.UUIDs;
2121
import org.elasticsearch.common.blobstore.BlobContainer;
22+
import org.elasticsearch.common.lucene.store.ESIndexInputTestCase;
2223
import org.elasticsearch.common.settings.Settings;
2324
import org.elasticsearch.common.unit.ByteSizeUnit;
2425
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -605,8 +606,14 @@ private void executeTestCase(
605606
final TriConsumer<String, byte[], SearchableSnapshotDirectory> test
606607
) throws Exception {
607608

609+
final String fileName;
610+
if (SearchableSnapshots.SNAPSHOT_PARTIAL_SETTING.get(indexSettings)) {
611+
fileName = randomAlphaOfLength(10) + randomValueOtherThan(".cfs", ESIndexInputTestCase::randomFileExtension);
612+
} else {
613+
fileName = randomAlphaOfLength(10) + randomFileExtension();
614+
}
615+
608616
final byte[] fileContent = randomByteArrayOfLength(randomIntBetween(10, MAX_FILE_LENGTH));
609-
final String fileName = randomAlphaOfLength(10) + randomFileExtension();
610617
final SnapshotId snapshotId = new SnapshotId("_name", "_uuid");
611618
final IndexId indexId = new IndexId("_name", "_uuid");
612619
final ShardId shardId = new ShardId("_name", "_uuid", 0);

0 commit comments

Comments
 (0)