Class BlockReaderFactory
java.lang.Object
org.apache.hadoop.hdfs.client.impl.BlockReaderFactory
- All Implemented Interfaces:
ShortCircuitCache.ShortCircuitReplicaCreator
@Private
public class BlockReaderFactory
extends Object
implements ShortCircuitCache.ShortCircuitReplicaCreator
Utility class to create BlockReader implementations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a BlockReader with the given options.Fetch a pair of short-circuit block descriptors from a local DataNode.static StringgetFileName(InetSocketAddress s, String poolId, long blockId) File name to print when accessing a block directly (from servlets)setAllowShortCircuitLocalReads(boolean allowShortCircuitLocalReads) setBlock(ExtendedBlock block) setBlockToken(org.apache.hadoop.security.token.Token<BlockTokenIdentifier> token) setCachingStrategy(CachingStrategy cachingStrategy) setClientCacheContext(ClientContext clientContext) setClientName(String clientName) setConfiguration(org.apache.hadoop.conf.Configuration configuration) setDatanodeInfo(DatanodeInfo datanode) static voidsetFileName(String fileName) setInetSocketAddress(InetSocketAddress inetSocketAddress) setLength(long length) setRemotePeerFactory(RemotePeerFactory remotePeerFactory) setStartOffset(long startOffset) setStorageType(org.apache.hadoop.fs.StorageType storageType) setUserGroupInformation(org.apache.hadoop.security.UserGroupInformation userGroupInformation) setVerifyChecksum(boolean verifyChecksum) toString()
-
Constructor Details
-
BlockReaderFactory
-
-
Method Details
-
setFileName
-
setBlock
-
setBlockToken
public BlockReaderFactory setBlockToken(org.apache.hadoop.security.token.Token<BlockTokenIdentifier> token) -
setStartOffset
-
setVerifyChecksum
-
setClientName
-
setDatanodeInfo
-
setStorageType
-
setAllowShortCircuitLocalReads
-
setClientCacheContext
-
setLength
-
setCachingStrategy
-
setInetSocketAddress
-
setUserGroupInformation
public BlockReaderFactory setUserGroupInformation(org.apache.hadoop.security.UserGroupInformation userGroupInformation) -
setRemotePeerFactory
-
setConfiguration
-
setFailureInjectorForTesting
@VisibleForTesting public static void setFailureInjectorForTesting(BlockReaderFactory.FailureInjector injector) -
build
Build a BlockReader with the given options. This function will do the best it can to create a block reader that meets all of our requirements. We prefer short-circuit block readers (BlockReaderLocal and BlockReaderLocalLegacy) over remote ones, since the former avoid the overhead of socket communication. If short-circuit is unavailable, our next fallback is data transfer over UNIX domain sockets, if dfs.client.domain.socket.data.traffic has been enabled. If that doesn't work, we will try to create a remote block reader that operates over TCP sockets. There are a few caches that are important here. The ShortCircuitCache stores file descriptor objects which have been passed from the DataNode. The DomainSocketFactory stores information about UNIX domain socket paths that we not been able to use in the past, so that we don't waste time retrying them over and over. (Like all the caches, it does have a timeout, though.) The PeerCache stores peers that we have used in the past. If we can reuse one of these peers, we avoid the overhead of re-opening a socket. However, if the socket has been timed out on the remote end, our attempt to reuse the socket may end with an IOException. For that reason, we limit our attempts at socket reuse to dfs.client.cached.conn.retry times. After that, we create new sockets. This avoids the problem where a thread tries to talk to a peer that it hasn't talked to in a while, and has to clean out every entry in a socket cache full of stale entries.- Returns:
- The new BlockReader. We will not return null.
- Throws:
org.apache.hadoop.security.token.SecretManager.InvalidToken- If the block token was invalid. InvalidEncryptionKeyException If the encryption key was invalid. Other IOException If there was another problem.IOException
-
createShortCircuitReplicaInfo
Fetch a pair of short-circuit block descriptors from a local DataNode.- Specified by:
createShortCircuitReplicaInfoin interfaceShortCircuitCache.ShortCircuitReplicaCreator- Returns:
- Null if we could not communicate with the datanode, a new ShortCircuitReplicaInfo object otherwise. ShortCircuitReplicaInfo objects may contain either an InvalidToken exception, or a ShortCircuitReplica object ready to use.
-
toString
-
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
-