示例#1
0
        /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"/>
        private BlockReader GetBlockReaderLocal()
        {
            if (Log.IsTraceEnabled())
            {
                Log.Trace(this + ": trying to construct a BlockReaderLocal " + "for short-circuit reads."
                          );
            }
            if (pathInfo == null)
            {
                pathInfo = clientContext.GetDomainSocketFactory().GetPathInfo(inetSocketAddress,
                                                                              conf);
            }
            if (!pathInfo.GetPathState().GetUsableForShortCircuit())
            {
                PerformanceAdvisory.Log.Debug(this + ": " + pathInfo + " is not " + "usable for short circuit; giving up on BlockReaderLocal."
                                              );
                return(null);
            }
            ShortCircuitCache cache = clientContext.GetShortCircuitCache();
            ExtendedBlockId   key   = new ExtendedBlockId(block.GetBlockId(), block.GetBlockPoolId
                                                              ());
            ShortCircuitReplicaInfo info = cache.FetchOrCreate(key, this);

            SecretManager.InvalidToken exc = info.GetInvalidTokenException();
            if (exc != null)
            {
                if (Log.IsTraceEnabled())
                {
                    Log.Trace(this + ": got InvalidToken exception while trying to " + "construct BlockReaderLocal via "
                              + pathInfo.GetPath());
                }
                throw exc;
            }
            if (info.GetReplica() == null)
            {
                if (Log.IsTraceEnabled())
                {
                    PerformanceAdvisory.Log.Debug(this + ": failed to get " + "ShortCircuitReplica. Cannot construct "
                                                  + "BlockReaderLocal via " + pathInfo.GetPath());
                }
                return(null);
            }
            return(new BlockReaderLocal.Builder(conf).SetFilename(fileName).SetBlock(block).SetStartOffset
                       (startOffset).SetShortCircuitReplica(info.GetReplica()).SetVerifyChecksum(verifyChecksum
                                                                                                 ).SetCachingStrategy(cachingStrategy).SetStorageType(storageType).Build());
        }
示例#2
0
 /// <summary>Fetch a pair of short-circuit block descriptors from a local DataNode.</summary>
 /// <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.
 /// </returns>
 public virtual ShortCircuitReplicaInfo CreateShortCircuitReplicaInfo()
 {
     if (createShortCircuitReplicaInfoCallback != null)
     {
         ShortCircuitReplicaInfo info = createShortCircuitReplicaInfoCallback.CreateShortCircuitReplicaInfo
                                            ();
         if (info != null)
         {
             return(info);
         }
     }
     if (Log.IsTraceEnabled())
     {
         Log.Trace(this + ": trying to create ShortCircuitReplicaInfo.");
     }
     BlockReaderFactory.BlockReaderPeer curPeer;
     while (true)
     {
         curPeer = NextDomainPeer();
         if (curPeer == null)
         {
             break;
         }
         if (curPeer.fromCache)
         {
             remainingCacheTries--;
         }
         DomainPeer           peer  = (DomainPeer)curPeer.peer;
         ShortCircuitShm.Slot slot  = null;
         ShortCircuitCache    cache = clientContext.GetShortCircuitCache();
         try
         {
             MutableBoolean usedPeer = new MutableBoolean(false);
             slot = cache.AllocShmSlot(datanode, peer, usedPeer, new ExtendedBlockId(block.GetBlockId
                                                                                         (), block.GetBlockPoolId()), clientName);
             if (usedPeer.BooleanValue())
             {
                 if (Log.IsTraceEnabled())
                 {
                     Log.Trace(this + ": allocShmSlot used up our previous socket " + peer.GetDomainSocket
                                   () + ".  Allocating a new one...");
                 }
                 curPeer = NextDomainPeer();
                 if (curPeer == null)
                 {
                     break;
                 }
                 peer = (DomainPeer)curPeer.peer;
             }
             ShortCircuitReplicaInfo info = RequestFileDescriptors(peer, slot);
             clientContext.GetPeerCache().Put(datanode, peer);
             return(info);
         }
         catch (IOException e)
         {
             if (slot != null)
             {
                 cache.FreeSlot(slot);
             }
             if (curPeer.fromCache)
             {
                 // Handle an I/O error we got when using a cached socket.
                 // These are considered less serious, because the socket may be stale.
                 if (Log.IsDebugEnabled())
                 {
                     Log.Debug(this + ": closing stale domain peer " + peer, e);
                 }
                 IOUtils.Cleanup(Log, peer);
             }
             else
             {
                 // Handle an I/O error we got when using a newly created socket.
                 // We temporarily disable the domain socket path for a few minutes in
                 // this case, to prevent wasting more time on it.
                 Log.Warn(this + ": I/O error requesting file descriptors.  " + "Disabling domain socket "
                          + peer.GetDomainSocket(), e);
                 IOUtils.Cleanup(Log, peer);
                 clientContext.GetDomainSocketFactory().DisableDomainSocketPath(pathInfo.GetPath()
                                                                                );
                 return(null);
             }
         }
     }
     return(null);
 }