/// <summary>Get a RemoteBlockReader that communicates over a TCP socket.</summary> /// <returns> /// The new BlockReader. We will not return null, but instead throw /// an exception if this fails. /// </returns> /// <exception cref="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. /// </exception> /// <exception cref="System.IO.IOException"/> private BlockReader GetRemoteBlockReaderFromTcp() { if (Log.IsTraceEnabled()) { Log.Trace(this + ": trying to create a remote block reader from a " + "TCP socket" ); } BlockReader blockReader = null; while (true) { BlockReaderFactory.BlockReaderPeer curPeer = null; Peer peer = null; try { curPeer = NextTcpPeer(); if (curPeer.fromCache) { remainingCacheTries--; } peer = curPeer.peer; blockReader = GetRemoteBlockReader(peer); return(blockReader); } catch (IOException ioe) { if (IsSecurityException(ioe)) { if (Log.IsTraceEnabled()) { Log.Trace(this + ": got security exception while constructing " + "a remote block reader from " + peer, ioe); } throw; } if ((curPeer != null) && curPeer.fromCache) { // Handle an I/O error we got when using a cached peer. These are // considered less serious, because the underlying socket may be // stale. if (Log.IsDebugEnabled()) { Log.Debug("Closed potentially stale remote peer " + peer, ioe); } } else { // Handle an I/O error we got when using a newly created peer. Log.Warn("I/O error constructing remote block reader.", ioe); throw; } } finally { if (blockReader == null) { IOUtils.Cleanup(Log, peer); } } } }
/// <summary>Get a RemoteBlockReader that communicates over a UNIX domain socket.</summary> /// <returns> /// The new BlockReader, or null if we failed to create the block /// reader. /// </returns> /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"> /// If the block token was invalid. /// Potentially other security-related execptions. /// </exception> /// <exception cref="System.IO.IOException"/> private BlockReader GetRemoteBlockReaderFromDomain() { if (pathInfo == null) { pathInfo = clientContext.GetDomainSocketFactory().GetPathInfo(inetSocketAddress, conf); } if (!pathInfo.GetPathState().GetUsableForDataTransfer()) { PerformanceAdvisory.Log.Debug(this + ": not trying to create a " + "remote block reader because the UNIX domain socket at " + pathInfo + " is not usable."); return(null); } if (Log.IsTraceEnabled()) { Log.Trace(this + ": trying to create a remote block reader from the " + "UNIX domain socket at " + pathInfo.GetPath()); } while (true) { BlockReaderFactory.BlockReaderPeer curPeer = NextDomainPeer(); if (curPeer == null) { break; } if (curPeer.fromCache) { remainingCacheTries--; } DomainPeer peer = (DomainPeer)curPeer.peer; BlockReader blockReader = null; try { blockReader = GetRemoteBlockReader(peer); return(blockReader); } catch (IOException ioe) { IOUtils.Cleanup(Log, peer); if (IsSecurityException(ioe)) { if (Log.IsTraceEnabled()) { Log.Trace(this + ": got security exception while constructing " + "a remote block reader from the unix domain socket at " + pathInfo.GetPath(), ioe); } throw; } if (curPeer.fromCache) { // Handle an I/O error we got when using a cached peer. These are // considered less serious, because the underlying socket may be stale. if (Log.IsDebugEnabled()) { Log.Debug("Closed potentially stale domain peer " + peer, ioe); } } else { // Handle an I/O error we got when using a newly created domain peer. // We temporarily disable the domain socket path for a few minutes in // this case, to prevent wasting more time on it. Log.Warn("I/O error constructing remote block reader. Disabling " + "domain socket " + peer.GetDomainSocket(), ioe); clientContext.GetDomainSocketFactory().DisableDomainSocketPath(pathInfo.GetPath() ); return(null); } } finally { if (blockReader == null) { IOUtils.Cleanup(Log, peer); } } } return(null); }