public ReadaheadRequest readaheadStream ( String identifier , FileDescriptor fd , long curPos , long readaheadLength , long maxOffsetToRead , ReadaheadRequest lastReadahead ) { Preconditions . checkArgument ( curPos <= maxOffsetToRead , "Readahead position %s higher than maxOffsetToRead %s" , curPos , maxOffsetToRead ) ; if ( readaheadLength <= 0 ) { return null ; } long lastOffset = Long . MIN_VALUE ; if ( lastReadahead != null ) { lastOffset = lastReadahead . getOffset ( ) ; } // trigger each readahead when we have reached the halfway mark // in the previous readahead. This gives the system time // to satisfy the readahead before we start reading the data. long nextOffset = lastOffset + readaheadLength / 2 ; if ( curPos >= nextOffset ) { // cancel any currently pending readahead, to avoid // piling things up in the queue. Each reader should have at most // one outstanding request in the queue. if ( lastReadahead != null ) { lastReadahead . cancel ( ) ; lastReadahead = null ; } long length = Math . min ( readaheadLength , maxOffsetToRead - curPos ) ; if ( length <= 0 ) { // we've reached the end of the stream return null ; } return submitReadahead ( identifier , fd , curPos , length ) ; } else { return lastReadahead ; } }
Issue a request to readahead on the given file descriptor .