public static LocationPair getBlockLocation ( Codec codec , FileSystem srcFs , Path srcFile , int blockIdxInFile , Configuration conf , List < FileStatus > lfs ) throws IOException { int stripeIdx = 0 ; int blockIdxInStripe = 0 ; int blockIdx = blockIdxInFile ; if ( codec . isDirRaid ) { Path parentPath = srcFile . getParent ( ) ; if ( lfs == null ) { lfs = RaidNode . listDirectoryRaidFileStatus ( conf , srcFs , parentPath ) ; } if ( lfs == null ) { throw new IOException ( "Couldn't list files under " + parentPath ) ; } int blockNum = 0 ; Path qSrcFile = srcFs . makeQualified ( srcFile ) ; for ( FileStatus fsStat : lfs ) { if ( ! fsStat . getPath ( ) . equals ( qSrcFile ) ) { blockNum += RaidNode . getNumBlocks ( fsStat ) ; } else { blockNum += blockIdxInFile ; break ; } } blockIdx = blockNum ; } stripeIdx = blockIdx / codec . stripeLength ; blockIdxInStripe = blockIdx % codec . stripeLength ; return new LocationPair ( stripeIdx , blockIdxInStripe , lfs ) ; }
Given a block in the file and specific codec return the LocationPair object which contains id of the stripe it belongs to and its location in the stripe