Skip to content

Commit b15a8ff

Browse files
Fix Searchable Snapshot Test Range Size Overflow (#74113) (#74238)
Page alignment of the setting value can push it past the maximum since we round up. Closes #74016
1 parent 4782caf commit b15a8ff

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLengthBetween;
7373
import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.randomPopulateAndReads;
74+
import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.SharedBytes.PAGE_SIZE;
7475
import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.SharedBytes.pageAligned;
7576

7677
public abstract class AbstractSearchableSnapshotsTestCase extends ESIndexInputTestCase {
@@ -211,25 +212,20 @@ protected static ByteSizeValue randomFrozenCacheSize() {
211212
* @return a random {@link ByteSizeValue} that can be used to set {@link CacheService#SNAPSHOT_CACHE_RANGE_SIZE_SETTING}
212213
*/
213214
protected static ByteSizeValue randomCacheRangeSize() {
214-
return pageAligned(
215-
new ByteSizeValue(
216-
randomLongBetween(
217-
CacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE.getBytes(),
218-
CacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE.getBytes()
219-
)
220-
)
221-
);
215+
return pageAlignedBetween(CacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE, CacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE);
222216
}
223217

224218
protected static ByteSizeValue randomFrozenCacheRangeSize() {
225-
return pageAligned(
226-
new ByteSizeValue(
227-
randomLongBetween(
228-
FrozenCacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE.getBytes(),
229-
FrozenCacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE.getBytes()
230-
)
231-
)
232-
);
219+
return pageAlignedBetween(FrozenCacheService.MIN_SNAPSHOT_CACHE_RANGE_SIZE, FrozenCacheService.MAX_SNAPSHOT_CACHE_RANGE_SIZE);
220+
}
221+
222+
private static ByteSizeValue pageAlignedBetween(ByteSizeValue min, ByteSizeValue max) {
223+
ByteSizeValue aligned = pageAligned(new ByteSizeValue(randomLongBetween(min.getBytes(), max.getBytes())));
224+
if (aligned.compareTo(max) > 0) {
225+
// minus one page in case page alignment moved us past the max setting value
226+
return new ByteSizeValue(aligned.getBytes() - PAGE_SIZE);
227+
}
228+
return aligned;
233229
}
234230

235231
protected static SearchableSnapshotRecoveryState createRecoveryState(boolean finalizedDone) {

0 commit comments

Comments
 (0)