/** removes a parity block in the specified stripe */ private void removeParityBlock(Path filePath, int stripe) throws IOException { // find parity file ParityFilePair ppair = ParityFilePair.getParityFile(ErasureCodeType.XOR, filePath, conf); String parityPathStr = ppair.getPath().toUri().getPath(); LOG.info("parity path: " + parityPathStr); FileSystem parityFS = ppair.getFileSystem(); if (!(parityFS instanceof DistributedFileSystem)) { throw new IOException("parity file is not on distributed file system"); } DistributedFileSystem parityDFS = (DistributedFileSystem) parityFS; // now corrupt the block corresponding to the stripe selected FileStatus parityFileStatus = parityDFS.getFileStatus(new Path(parityPathStr)); long parityBlockSize = parityFileStatus.getBlockSize(); long parityFileLength = parityFileStatus.getLen(); long parityFileLengthInBlocks = (parityFileLength / parityBlockSize) + (((parityFileLength % parityBlockSize) == 0) ? 0L : 1L); if (parityFileLengthInBlocks <= stripe) { throw new IOException( "selected stripe " + stripe + " but parity file only has " + parityFileLengthInBlocks + " blocks"); } if (parityBlockSize != BLOCK_SIZE) { throw new IOException( "file block size is " + BLOCK_SIZE + " but parity file block size is " + parityBlockSize); } LocatedBlocks parityFileBlocks = parityDFS.getClient().namenode.getBlockLocations(parityPathStr, 0, parityFileLength); if (parityFileBlocks.locatedBlockCount() != parityFileLengthInBlocks) { throw new IOException( "expected " + parityFileLengthInBlocks + " parity file blocks but got " + parityFileBlocks.locatedBlockCount() + " blocks"); } LocatedBlock parityFileBlock = parityFileBlocks.get(stripe); removeAndReportBlock(parityDFS, new Path(parityPathStr), parityFileBlock); LOG.info("removed parity file block/stripe " + stripe + " for " + filePath.toString()); }
static { ParityFilePair.disableCacheUsedInTestOnly(); }