private static void checkParityBlocks ( final Path filePath , final Map < Integer , Integer > corruptBlocksPerStripe , final long blockSize , final long startStripeIdx , final long endStripeIdx , final long numStripes , final RaidInfo raidInfo ) throws IOException { // get the blocks of the parity file // because of har, multiple blocks may be returned as one container block BlockLocation [ ] containerBlocks = getParityBlocks ( filePath , blockSize , numStripes , raidInfo ) ; long parityStripeLength = blockSize * ( ( long ) raidInfo . parityBlocksPerStripe ) ; long parityBlocksFound = 0L ; for ( BlockLocation cb : containerBlocks ) { if ( cb . getLength ( ) % blockSize != 0 ) { throw new IOException ( "container block size is not " + "multiple of parity block size" ) ; } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "found container with offset " + cb . getOffset ( ) + ", length " + cb . getLength ( ) ) ; } for ( long offset = cb . getOffset ( ) ; offset < cb . getOffset ( ) + cb . getLength ( ) ; offset += blockSize ) { long block = offset / blockSize ; int stripe = ( int ) ( offset / parityStripeLength ) ; if ( stripe < 0 ) { // before the beginning of the parity file continue ; } if ( stripe >= numStripes ) { // past the end of the parity file break ; } parityBlocksFound ++ ; if ( stripe < startStripeIdx || stripe >= endStripeIdx ) { continue ; } if ( isBlockCorrupt ( cb ) ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "parity file for " + filePath . toString ( ) + " corrupt in block " + block + ", stripe " + stripe + "/" + numStripes ) ; } incCorruptBlocksPerStripe ( corruptBlocksPerStripe , stripe ) ; } else { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "parity file for " + filePath . toString ( ) + " OK in block " + block + ", stripe " + stripe + "/" + numStripes ) ; } } } } long parityBlocksExpected = raidInfo . parityBlocksPerStripe * numStripes ; if ( parityBlocksFound != parityBlocksExpected ) { throw new IOException ( "expected " + parityBlocksExpected + " parity blocks but got " + parityBlocksFound ) ; } }
checks the parity blocks for a given file and modifies corruptBlocksPerStripe accordingly