int realLen = length;
if ((position + length) > filelen) {
realLen = (int)(filelen - position);
}
DFSReadProfilingData pData = DFSClient.getDFSReadProfilingData();
// determine the block and byte range within the block
// corresponding to position and realLen
List<LocatedBlock> blockRange = getBlockRange(position, realLen);
if (!tryPreadFromLocal(blockRange, position, buffer, offset, length,
realLen, start)) {
// non-local or multiple block read.
int remaining = realLen;
for (LocatedBlock blk : blockRange) {
long targetStart = position - blk.getStartOffset();
long bytesToRead = Math.min(remaining, blk.getBlockSize() - targetStart);
if (dfsClient.allowParallelReads && dfsClient.parallelReadsThreadPool != null) {
fetchBlockByteRangeSpeculative(blk, targetStart,
targetStart + bytesToRead - 1, buffer, offset,
options);
} else {
if (pData != null) {
cliData = new FSClientReadProfilingData();
pData.addDFSClientReadProfilingData(cliData);
cliData.startRead();
}
fetchBlockByteRange(blk, targetStart,
targetStart + bytesToRead - 1, buffer, offset,