3333import java .io .InputStream ;
3434import java .nio .ByteBuffer ;
3535import java .nio .channels .FileChannel ;
36- import java .util .List ;
3736import java .util .Locale ;
3837import java .util .concurrent .CompletableFuture ;
3938import 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