HDFS中DataNode获取数据函数


BlockReceiver 函数, receivePacket()函数

最终获取的数据包写入磁盘

try {
if (!finalized) {
//finally write to the disk :
out.write(pktBuf, dataOff, len);

// If this is a partial chunk, then verify that this is the only
// chunk in the packet. Calculate new crc for this chunk.
if (partialCrc != null) {
if (len > bytesPerChecksum) {
throw new IOException("Got wrong length during writeBlock(" +
block + ") from " + inAddr + " " +
"A packet can have only one partial chunk."+
" len = " + len +
" bytesPerChecksum " + bytesPerChecksum);
}
partialCrc.update(pktBuf, dataOff, len);
byte[] buf = FSOutputSummer.convertToByteStream(partialCrc, checksumSize);
checksumOut.write(buf);
LOG.debug("Writing out partial crc for data len " + len);
partialCrc = null;
} else {
checksumOut.write(pktBuf, checksumOff, checksumLen);
}
datanode.myMetrics.incrBytesWritten(len);


/// flush entire packet before sending ack
flush();

// update length only after flush to disk
datanode.data.setVisibleLength(block, offsetInBlock);
}
} catch (IOException iex) {
datanode.checkDiskError(iex);
throw iex;
}

你可能感兴趣的:(HDFS中DataNode获取数据函数)