java.io.Closeable, java.lang.AutoCloseable, org.apache.hadoop.fs.ByteBufferPositionedReadable, org.apache.hadoop.fs.ByteBufferReadable, org.apache.hadoop.fs.CanSetDropBehind, org.apache.hadoop.fs.CanSetReadahead, org.apache.hadoop.fs.CanUnbuffer, org.apache.hadoop.fs.HasEnhancedByteBufferAccess, org.apache.hadoop.fs.PositionedReadable, org.apache.hadoop.fs.Seekable, org.apache.hadoop.fs.StreamCapabilitiesDFSStripedInputStream@Private
public class DFSInputStream
extends org.apache.hadoop.fs.FSInputStream
implements org.apache.hadoop.fs.ByteBufferReadable, org.apache.hadoop.fs.CanSetDropBehind, org.apache.hadoop.fs.CanSetReadahead, org.apache.hadoop.fs.HasEnhancedByteBufferAccess, org.apache.hadoop.fs.CanUnbuffer, org.apache.hadoop.fs.StreamCapabilities, org.apache.hadoop.fs.ByteBufferPositionedReadable
| Modifier and Type | Field | Description |
|---|---|---|
protected long |
blockEnd |
|
protected CachingStrategy |
cachingStrategy |
|
protected java.util.concurrent.atomic.AtomicBoolean |
closed |
|
protected LocatedBlock |
currentLocatedBlock |
|
protected DFSClient |
dfsClient |
|
protected int |
failures |
This variable tracks the number of failures since the start of the
most recent user-facing operation.
|
protected java.lang.Object |
infoLock |
|
protected LocatedBlocks |
locatedBlocks |
|
protected long |
pos |
|
protected ReadStatistics |
readStatistics |
|
protected java.lang.String |
src |
|
static boolean |
tcpReadsDisabledForTesting |
|
protected boolean |
verifyChecksum |
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
addToLocalDeadNodes(DatanodeInfo dnInfo) |
|
int |
available() |
Return the size of the remaining available bytes
if the size is less than or equal to
Integer.MAX_VALUE,
otherwise, return Integer.MAX_VALUE. |
void |
clearReadStatistics() |
Clear statistics about the reads which this DFSInputStream has done.
|
void |
close() |
Close it down!
|
protected void |
closeCurrentBlockReaders() |
|
protected LocatedBlock |
fetchBlockAt(long offset) |
Fetch a block from namenode and cache it
|
protected void |
fetchBlockByteRange(LocatedBlock block,
long start,
long end,
java.nio.ByteBuffer buf,
DFSUtilClient.CorruptedBlocks corruptedBlocks) |
|
java.util.List<LocatedBlock> |
getAllBlocks() |
Return collection of blocks that has already been located.
|
protected org.apache.hadoop.hdfs.DFSInputStream.DNAddrPair |
getBestNodeDNAddrPair(LocatedBlock block,
java.util.Collection<DatanodeInfo> ignoredNodes) |
Get the best node from which to stream the data.
|
protected LocatedBlock |
getBlockAt(long offset) |
Get block at the specified position.
|
protected BlockReader |
getBlockReader(LocatedBlock targetBlock,
long offsetInBlock,
long length,
java.net.InetSocketAddress targetAddr,
org.apache.hadoop.fs.StorageType storageType,
DatanodeInfo datanode) |
|
ExtendedBlock |
getCurrentBlock() |
Returns the block containing the target position.
|
protected int |
getCurrentBlockLocationsLength() |
|
DatanodeInfo |
getCurrentDatanode() |
Returns the datanode from which the stream is currently reading.
|
protected DFSClient |
getDFSClient() |
|
org.apache.hadoop.fs.FileEncryptionInfo |
getFileEncryptionInfo() |
|
long |
getFileLength() |
|
long |
getHedgedReadOpsLoopNumForTesting() |
|
protected java.util.concurrent.ConcurrentHashMap<DatanodeInfo,DatanodeInfo> |
getLocalDeadNodes() |
|
protected LocatedBlocks |
getLocatedBlocks() |
|
long |
getPos() |
|
ReadStatistics |
getReadStatistics() |
Get statistics about the reads which this DFSInputStream has done.
|
protected java.lang.String |
getSrc() |
|
boolean |
hasCapability(java.lang.String capability) |
|
void |
mark(int readLimit) |
|
boolean |
markSupported() |
We definitely don't support marks
|
protected void |
maybeRegisterBlockRefresh() |
Many DFSInputStreams can be opened and closed in quick succession, in which case
they would be registered/deregistered but never need to be refreshed.
|
int |
read() |
|
int |
read(byte[] buf,
int off,
int len) |
Read the entire buffer.
|
int |
read(long position,
byte[] buffer,
int offset,
int length) |
Read bytes starting from the specified position.
|
int |
read(long position,
java.nio.ByteBuffer buf) |
|
int |
read(java.nio.ByteBuffer buf) |
|
java.nio.ByteBuffer |
read(org.apache.hadoop.io.ByteBufferPool bufferPool,
int maxLength,
java.util.EnumSet<org.apache.hadoop.fs.ReadOption> opts) |
|
void |
readFully(long position,
java.nio.ByteBuffer buf) |
|
protected int |
readWithStrategy(org.apache.hadoop.hdfs.ReaderStrategy strategy) |
|
protected LocatedBlock |
refreshLocatedBlock(LocatedBlock block) |
Refresh cached block locations.
|
void |
releaseBuffer(java.nio.ByteBuffer buffer) |
|
protected void |
removeFromLocalDeadNodes(DatanodeInfo dnInfo) |
|
protected void |
reportCheckSumFailure(DFSUtilClient.CorruptedBlocks corruptedBlocks,
int dataNodeCount,
boolean isStriped) |
DFSInputStream reports checksum failure.
|
protected void |
reportLostBlock(LocatedBlock lostBlock,
java.util.Collection<DatanodeInfo> ignoredNodes) |
Warn the user of a lost block
|
void |
reset() |
|
void |
seek(long targetPos) |
Seek to a new arbitrary location
|
boolean |
seekToNewSource(long targetPos) |
Seek to given position on a node other than the current node.
|
void |
setDropBehind(java.lang.Boolean dropBehind) |
|
void |
setReadahead(java.lang.Long readahead) |
|
long |
skip(long n) |
|
protected static boolean |
tokenRefetchNeeded(java.io.IOException ex,
java.net.InetSocketAddress targetAddr) |
Should the block access token be refetched on an exception
|
void |
unbuffer() |
readFully, readFully, toString, validatePositionedReadArgsnullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTo@VisibleForTesting public static boolean tcpReadsDisabledForTesting
protected final DFSClient dfsClient
protected java.util.concurrent.atomic.AtomicBoolean closed
protected final java.lang.String src
protected final boolean verifyChecksum
protected LocatedBlock currentLocatedBlock
protected long pos
protected long blockEnd
protected LocatedBlocks locatedBlocks
protected CachingStrategy cachingStrategy
protected final ReadStatistics readStatistics
protected final java.lang.Object infoLock
protected int failures
protected void addToLocalDeadNodes(DatanodeInfo dnInfo)
protected void removeFromLocalDeadNodes(DatanodeInfo dnInfo)
protected java.util.concurrent.ConcurrentHashMap<DatanodeInfo,DatanodeInfo> getLocalDeadNodes()
protected DFSClient getDFSClient()
public long getFileLength()
public DatanodeInfo getCurrentDatanode()
public ExtendedBlock getCurrentBlock()
public java.util.List<LocatedBlock> getAllBlocks() throws java.io.IOException
java.io.IOExceptionprotected java.lang.String getSrc()
protected LocatedBlocks getLocatedBlocks()
protected LocatedBlock getBlockAt(long offset) throws java.io.IOException
offset - block corresponding to this offset in file is returnedjava.io.IOExceptionprotected LocatedBlock fetchBlockAt(long offset) throws java.io.IOException
java.io.IOExceptionprotected BlockReader getBlockReader(LocatedBlock targetBlock, long offsetInBlock, long length, java.net.InetSocketAddress targetAddr, org.apache.hadoop.fs.StorageType storageType, DatanodeInfo datanode) throws java.io.IOException
java.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeableclose in class java.io.InputStreamjava.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionprotected int readWithStrategy(org.apache.hadoop.hdfs.ReaderStrategy strategy)
throws java.io.IOException
java.io.IOExceptionprotected int getCurrentBlockLocationsLength()
public int read(@Nonnull
byte[] buf,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(java.nio.ByteBuffer buf)
throws java.io.IOException
read in interface org.apache.hadoop.fs.ByteBufferReadablejava.io.IOExceptionprotected org.apache.hadoop.hdfs.DFSInputStream.DNAddrPair getBestNodeDNAddrPair(LocatedBlock block, java.util.Collection<DatanodeInfo> ignoredNodes)
block - LocatedBlock, containing nodes in priority order.ignoredNodes - Do not choose nodes in this array (may be null)protected void reportLostBlock(LocatedBlock lostBlock, java.util.Collection<DatanodeInfo> ignoredNodes)
protected void fetchBlockByteRange(LocatedBlock block, long start, long end, java.nio.ByteBuffer buf, DFSUtilClient.CorruptedBlocks corruptedBlocks) throws java.io.IOException
java.io.IOExceptionprotected LocatedBlock refreshLocatedBlock(LocatedBlock block) throws java.io.IOException
block - The currently cached block locationsjava.io.IOException@VisibleForTesting public long getHedgedReadOpsLoopNumForTesting()
protected static boolean tokenRefetchNeeded(java.io.IOException ex,
java.net.InetSocketAddress targetAddr)
ex - Exception receivedtargetAddr - Target datanode address from where exception was receivedpublic int read(long position,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
read in interface org.apache.hadoop.fs.PositionedReadableread in class org.apache.hadoop.fs.FSInputStreamposition - start read from this positionbuffer - read bufferoffset - offset into bufferlength - number of bytes to readjava.io.IOExceptionprotected void reportCheckSumFailure(DFSUtilClient.CorruptedBlocks corruptedBlocks, int dataNodeCount, boolean isStriped)
corruptedBlocks - map of corrupted blocksdataNodeCount - number of data nodes who contains the block replicaspublic long skip(long n)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOExceptionpublic void seek(long targetPos)
throws java.io.IOException
seek in interface org.apache.hadoop.fs.Seekableseek in class org.apache.hadoop.fs.FSInputStreamjava.io.IOExceptionpublic boolean seekToNewSource(long targetPos)
throws java.io.IOException
seekToNewSource in interface org.apache.hadoop.fs.SeekableseekToNewSource in class org.apache.hadoop.fs.FSInputStreamjava.io.IOExceptionpublic long getPos()
getPos in interface org.apache.hadoop.fs.SeekablegetPos in class org.apache.hadoop.fs.FSInputStreampublic int available()
throws java.io.IOException
Integer.MAX_VALUE,
otherwise, return Integer.MAX_VALUE.available in class java.io.InputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.InputStreampublic void mark(int readLimit)
mark in class java.io.InputStreampublic void reset()
throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic int read(long position,
java.nio.ByteBuffer buf)
throws java.io.IOException
read in interface org.apache.hadoop.fs.ByteBufferPositionedReadablejava.io.IOExceptionpublic void readFully(long position,
java.nio.ByteBuffer buf)
throws java.io.IOException
readFully in interface org.apache.hadoop.fs.ByteBufferPositionedReadablejava.io.IOExceptionpublic ReadStatistics getReadStatistics()
public void clearReadStatistics()
public org.apache.hadoop.fs.FileEncryptionInfo getFileEncryptionInfo()
protected void closeCurrentBlockReaders()
public void setReadahead(java.lang.Long readahead)
throws java.io.IOException
setReadahead in interface org.apache.hadoop.fs.CanSetReadaheadjava.io.IOExceptionpublic void setDropBehind(java.lang.Boolean dropBehind)
throws java.io.IOException
setDropBehind in interface org.apache.hadoop.fs.CanSetDropBehindjava.io.IOExceptionpublic java.nio.ByteBuffer read(org.apache.hadoop.io.ByteBufferPool bufferPool,
int maxLength,
java.util.EnumSet<org.apache.hadoop.fs.ReadOption> opts)
throws java.io.IOException,
java.lang.UnsupportedOperationException
read in interface org.apache.hadoop.fs.HasEnhancedByteBufferAccessjava.io.IOExceptionjava.lang.UnsupportedOperationExceptionpublic void releaseBuffer(java.nio.ByteBuffer buffer)
releaseBuffer in interface org.apache.hadoop.fs.HasEnhancedByteBufferAccesspublic void unbuffer()
unbuffer in interface org.apache.hadoop.fs.CanUnbufferpublic boolean hasCapability(java.lang.String capability)
hasCapability in interface org.apache.hadoop.fs.StreamCapabilitiesprotected void maybeRegisterBlockRefresh()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.