private static LOGRESULTS doFileRaid ( Configuration conf , EncodingCandidate ec , Path destPath , Codec codec , Statistics statistics , Progressable reporter , boolean doSimulate , int targetRepl , int metaRepl ) throws IOException , InterruptedException { FileStatus stat = ec . srcStat ; Path p = stat . getPath ( ) ; FileSystem srcFs = p . getFileSystem ( conf ) ; // extract block locations from File system BlockLocation [ ] locations = srcFs . getFileBlockLocations ( stat , 0 , stat . getLen ( ) ) ; // if the file has fewer than 2 blocks, then nothing to do if ( locations . length <= 2 ) { return LOGRESULTS . NOACTION ; } // add up the raw disk space occupied by this file long diskSpace = 0 ; for ( BlockLocation l : locations ) { diskSpace += ( l . getLength ( ) * stat . getReplication ( ) ) ; } statistics . numProcessedBlocks += locations . length ; statistics . processedSize += diskSpace ; // generate parity file boolean parityGenerated = generateParityFile ( conf , ec , targetRepl , reporter , srcFs , destPath , codec , locations . length , stat . getReplication ( ) , metaRepl , stat . getBlockSize ( ) , null ) ; if ( ! parityGenerated ) { return LOGRESULTS . NOACTION ; } if ( ! doSimulate ) { if ( srcFs . setReplication ( p , ( short ) targetRepl ) == false ) { LOG . info ( "Error in reducing replication of " + p + " to " + targetRepl ) ; statistics . remainingSize += diskSpace ; return LOGRESULTS . FAILURE ; } ; } diskSpace = 0 ; for ( BlockLocation l : locations ) { diskSpace += ( l . getLength ( ) * targetRepl ) ; } statistics . remainingSize += diskSpace ; // the metafile will have this many number of blocks int numMeta = locations . length / codec . stripeLength ; if ( locations . length % codec . stripeLength != 0 ) { numMeta ++ ; } // we create numMeta for every file. This metablock has metaRepl # replicas. // the last block of the metafile might not be completely filled up, but we // ignore that for now. statistics . numMetaBlocks += ( numMeta * metaRepl ) ; statistics . metaSize += ( numMeta * metaRepl * stat . getBlockSize ( ) ) ; return LOGRESULTS . SUCCESS ; }
RAID an individual file