Class BlockReaderRemote
java.lang.Object
org.apache.hadoop.hdfs.client.impl.BlockReaderRemote
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.fs.ByteBufferReadable,BlockReader
This is a wrapper around connection to datanode
and understands checksum, offset etc.
Terminology:
- block
- The hdfs block, typically large (~64MB).
- chunk
- A block is divided into chunks, each comes with a checksum. We want transfers to be chunk-aligned, to be able to verify checksums.
- packet
- A grouping of chunks used for transport. It contains a header, followed by checksum data, followed by real data.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBlockReaderRemote(String file, long blockId, org.apache.hadoop.util.DataChecksum checksum, boolean verifyChecksum, long startOffset, long firstChunkOffset, long bytesToRead, Peer peer, DatanodeID datanodeID, PeerCache peerCache, int networkDistance) -
Method Summary
Modifier and TypeMethodDescriptionintReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream without performing network I/O.voidclose()Close the block reader.getClientMmap(EnumSet<org.apache.hadoop.fs.ReadOption> opts) Get a ClientMmap object for this BlockReader.org.apache.hadoop.util.DataChecksumstatic StringgetFileName(InetSocketAddress s, String poolId, long blockId) File name to print when accessing a block directly (from servlets)intReturn the network distance between local machine and the remote machine.getPeer()booleanstatic BlockReadernewBlockReader(String file, ExtendedBlock block, org.apache.hadoop.security.token.Token<BlockTokenIdentifier> blockToken, long startOffset, long len, boolean verifyChecksum, String clientName, Peer peer, DatanodeID datanodeID, PeerCache peerCache, CachingStrategy cachingStrategy, int networkDistance, org.apache.hadoop.conf.Configuration configuration) Create a new BlockReader specifically to satisfy a read.intread(byte[] buf, int off, int len) intread(ByteBuffer buf) intreadAll(byte[] buf, int offset, int len) Similar toBlockReader.readFully(byte[], int, int)except that it will not throw an exception on EOF.voidreadFully(byte[] buf, int off, int len) Read exactly the given amount of data, throwing an exception if EOF is reached before that amountlongskip(long n) Skip the given number of bytes
-
Constructor Details
-
BlockReaderRemote
protected BlockReaderRemote(String file, long blockId, org.apache.hadoop.util.DataChecksum checksum, boolean verifyChecksum, long startOffset, long firstChunkOffset, long bytesToRead, Peer peer, DatanodeID datanodeID, PeerCache peerCache, int networkDistance)
-
-
Method Details
-
getPeer
-
read
- Specified by:
readin interfaceBlockReader- Throws:
IOException
-
read
- Specified by:
readin interfaceorg.apache.hadoop.fs.ByteBufferReadable- Throws:
IOException
-
skip
Description copied from interface:BlockReaderSkip the given number of bytes- Specified by:
skipin interfaceBlockReader- Throws:
IOException
-
close
Description copied from interface:BlockReaderClose the block reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBlockReader- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getFileName
File name to print when accessing a block directly (from servlets)- Parameters:
s- Address of the block locationpoolId- Block pool ID of the blockblockId- Block ID of the block- Returns:
- string that has a file name for debug purposes
-
readAll
Description copied from interface:BlockReaderSimilar toBlockReader.readFully(byte[], int, int)except that it will not throw an exception on EOF. However, it differs from the simpleBlockReader.read(byte[], int, int)call in that it is guaranteed to read the data if it is available. In other words, if this call does not throw an exception, then either the buffer has been filled or the next call will return EOF.- Specified by:
readAllin interfaceBlockReader- Throws:
IOException
-
readFully
Description copied from interface:BlockReaderRead exactly the given amount of data, throwing an exception if EOF is reached before that amount- Specified by:
readFullyin interfaceBlockReader- Throws:
IOException
-
newBlockReader
public static BlockReader newBlockReader(String file, ExtendedBlock block, org.apache.hadoop.security.token.Token<BlockTokenIdentifier> blockToken, long startOffset, long len, boolean verifyChecksum, String clientName, Peer peer, DatanodeID datanodeID, PeerCache peerCache, CachingStrategy cachingStrategy, int networkDistance, org.apache.hadoop.conf.Configuration configuration) throws IOException Create a new BlockReader specifically to satisfy a read. This method also sends the OP_READ_BLOCK request.- Parameters:
file- File location.block- The block object.blockToken- The block token for security.startOffset- The read offset, relative to block head.len- The number of bytes to read.verifyChecksum- Whether to verify checksum.clientName- Client name.peer- The Peer to use.datanodeID- The DatanodeID this peer is connected to.peerCache- Caches TCP and UNIX domain sockets for reuse.cachingStrategy- Caching strategy to use when reading the block.networkDistance- Return the distance between two nodes by comparing their network paths.configuration- Configuration of client.- Returns:
- New BlockReader instance, or null on error.
- Throws:
IOException
-
available
public int available()Description copied from interface:BlockReaderReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream without performing network I/O. This may return more than what is actually present in the block.- Specified by:
availablein interfaceBlockReader
-
isShortCircuit
public boolean isShortCircuit()- Specified by:
isShortCircuitin interfaceBlockReader- Returns:
- true only if this is a short-circuit read. All short-circuit reads are also local.
-
getClientMmap
Description copied from interface:BlockReaderGet a ClientMmap object for this BlockReader.- Specified by:
getClientMmapin interfaceBlockReader- Parameters:
opts- The read options to use.- Returns:
- The ClientMmap object, or null if mmap is not supported.
-
getDataChecksum
public org.apache.hadoop.util.DataChecksum getDataChecksum()- Specified by:
getDataChecksumin interfaceBlockReader- Returns:
- The DataChecksum used by the read block
-
getNetworkDistance
public int getNetworkDistance()Description copied from interface:BlockReaderReturn the network distance between local machine and the remote machine.- Specified by:
getNetworkDistancein interfaceBlockReader
-