try {
LOG.info("Sending block " + block +
" from " + sock.getLocalSocketAddress().toString() +
" to " + sock.getRemoteSocketAddress().toString());
BlockSender blockSender =
new BlockSender(namespaceId, block, blockSize, 0, blockSize,
corruptChecksumOk, chunkOffsetOK, verifyChecksum,
transferToAllowed, dataTransferVersion >= DataTransferProtocol.PACKET_INCLUDE_VERSION_VERSION,
new BlockWithChecksumFileReader.InputStreamWithChecksumFactory() {
@Override
public InputStream createStream(long offset) throws IOException {
// we are passing 0 as the offset above,
// so we can safely ignore
// the offset passed
return blockContents;
}
@Override
public DataInputStream getChecksumStream() throws IOException {
return metadataIn;
}
@Override
public BlockDataFile.Reader getBlockDataFileReader()
throws IOException {
return BlockDataFile.getDummyDataFileFromFileChannel(
blockContents.getChannel()).getReader(null);
}
});
WriteBlockHeader header = new WriteBlockHeader(new VersionAndOpcode(
dataTransferVersion, DataTransferProtocol.OP_WRITE_BLOCK));
header.set(namespaceId, block.getBlockId(), block.getGenerationStamp(),
0, false, true, new DatanodeInfo(), 0, null, "");
header.writeVersionAndOpCode(out);
header.write(out);
blockSender.sendBlock(out, baseStream, null, progress);
LOG.info("Sent block " + block + " to " + datanode);
} finally {
sock.close();
out.close();