Skip to content

Commit c5b65bc

Browse files
committed
No need for a list with <= 1 element
1 parent f06e0ae commit c5b65bc

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/CachedBlobContainerIndexInput.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.InputStream;
3434
import java.nio.ByteBuffer;
3535
import java.nio.channels.FileChannel;
36-
import java.util.List;
3736
import java.util.Locale;
3837
import java.util.concurrent.CompletableFuture;
3938
import java.util.concurrent.atomic.AtomicLong;
@@ -157,7 +156,7 @@ protected void readInternal(ByteBuffer b) throws IOException {
157156
assert b.remaining() == length;
158157
}
159158

160-
final List<Tuple<Long, Long>> indexCacheMisses;
159+
final Tuple<Long, Long> indexCacheMiss; // null if not a miss
161160

162161
// We prefer to use the index cache if the recovery is not done yet
163162
if (directory.isRecoveryDone() == false) {
@@ -189,13 +188,13 @@ protected void readInternal(ByteBuffer b) throws IOException {
189188
// {start, end} ranges where positions are relative to the whole file.
190189
if (canBeFullyCached) {
191190
// if the index input is smaller than twice the size of the blob cache, it will be fully indexed
192-
indexCacheMisses = List.of(Tuple.tuple(0L, fileInfo.length()));
191+
indexCacheMiss = Tuple.tuple(0L, fileInfo.length());
193192
} else {
194-
indexCacheMisses = List.of(Tuple.tuple(0L, (long) BlobStoreCacheService.DEFAULT_SIZE));
193+
indexCacheMiss = Tuple.tuple(0L, (long) BlobStoreCacheService.DEFAULT_SIZE);
195194
}
196-
logger.trace("recovery cache miss for [{}], falling through with regions [{}]", this, indexCacheMisses);
195+
logger.trace("recovery cache miss for [{}], falling through with cache miss [{}]", this, indexCacheMiss);
197196
} else {
198-
indexCacheMisses = List.of();
197+
indexCacheMiss = null;
199198
}
200199

201200
try {
@@ -207,8 +206,8 @@ protected void readInternal(ByteBuffer b) throws IOException {
207206
final Tuple<Long, Long> endRangeToWrite = computeRange(position + length - 1);
208207
assert startRangeToWrite.v2() <= endRangeToWrite.v2() : startRangeToWrite + " vs " + endRangeToWrite;
209208
final Tuple<Long, Long> rangeToWrite = Tuple.tuple(
210-
Math.min(startRangeToWrite.v1(), indexCacheMisses.stream().mapToLong(Tuple::v1).max().orElse(Long.MAX_VALUE)),
211-
Math.max(endRangeToWrite.v2(), indexCacheMisses.stream().mapToLong(Tuple::v2).max().orElse(Long.MIN_VALUE))
209+
Math.min(startRangeToWrite.v1(), indexCacheMiss == null ? Long.MAX_VALUE : indexCacheMiss.v1()),
210+
Math.max(endRangeToWrite.v2(), indexCacheMiss == null ? Long.MIN_VALUE : indexCacheMiss.v2())
212211
);
213212

214213
assert rangeToWrite.v1() <= position && position + length <= rangeToWrite.v2() : "["
@@ -233,7 +232,7 @@ protected void readInternal(ByteBuffer b) throws IOException {
233232
return read;
234233
}, this::writeCacheFile, directory.cacheFetchAsyncExecutor());
235234

236-
for (Tuple<Long, Long> indexCacheMiss : indexCacheMisses) {
235+
if (indexCacheMiss != null) {
237236
cacheFile.populateAndRead(indexCacheMiss, indexCacheMiss, channel -> {
238237
final int indexCacheMissLength = Math.toIntExact(indexCacheMiss.v2() - indexCacheMiss.v1());
239238

0 commit comments

Comments
 (0)