public CRC32 recoverParityBlockToStream ( FileSystem fs , FileStatus srcStat , long blockSize , Path parityFile , long corruptOffset , OutputStream out , Progressable progress ) throws IOException { LOG . info ( "Recovering parity block" + parityFile + ":" + corruptOffset ) ; Path srcFile = srcStat . getPath ( ) ; // Get the start offset of the corrupt block. corruptOffset = ( corruptOffset / blockSize ) * blockSize ; // Output streams to each block in the parity file stripe. OutputStream [ ] outs = new OutputStream [ codec . parityLength ] ; long indexOfCorruptBlockInParityStripe = ( corruptOffset / blockSize ) % codec . parityLength ; LOG . info ( "Index of corrupt block in parity stripe: " + indexOfCorruptBlockInParityStripe ) ; CRC32 [ ] crcOuts = null ; if ( checksumStore != null ) { crcOuts = new CRC32 [ codec . parityLength ] ; } // Create a real output stream for the block we want to recover, // and create null streams for the rest. for ( int i = 0 ; i < codec . parityLength ; i ++ ) { if ( indexOfCorruptBlockInParityStripe == i ) { outs [ i ] = out ; if ( checksumStore != null ) { crcOuts [ i ] = new CRC32 ( ) ; } } else { outs [ i ] = new NullOutputStream ( ) ; } } // Get the stripe index and start offset of stripe. long stripeIdx = corruptOffset / ( codec . parityLength * blockSize ) ; StripeReader sReader = StripeReader . getStripeReader ( codec , conf , blockSize , fs , stripeIdx , srcStat ) ; // Get input streams to each block in the source file stripe. assert sReader . hasNext ( ) == true ; InputStream [ ] blocks = sReader . getNextStripeInputs ( ) . getInputs ( ) ; LOG . info ( "Starting recovery by using source stripe " + srcFile + ": stripe " + stripeIdx ) ; try { // Read the data from the blocks and write to the parity file. encodeStripe ( blocks , blockSize , outs , crcOuts , progress , false , null ) ; if ( checksumStore != null ) { return crcOuts [ ( int ) indexOfCorruptBlockInParityStripe ] ; } else { return null ; } } finally { RaidUtils . closeStreams ( blocks ) ; } }
Recovers a corrupt block in a parity file to a local file .