public bool Get()
            {
                MutableBoolean finished = new MutableBoolean(false);

                cache.Accept(new _CacheVisitor_410(finished));
                return(finished.BooleanValue());
            }
Exemple #2
0
            public bool Get()
            {
                MutableBoolean done = new MutableBoolean(false);

                try
                {
                    cache.GetDfsClientShmManager().Visit(new _Visitor_463(done, datanode));
                }
                catch (IOException e)
                {
                    TestShortCircuitCache.Log.Error("error running visitor", e);
                }
                return(done.BooleanValue());
            }
Exemple #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAllocShm()
        {
            BlockReaderTestUtil.EnableShortCircuitShmTracing();
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            Configuration            conf    = CreateShortCircuitConf("testAllocShm", sockDir);
            MiniDFSCluster           cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            DistributedFileSystem fs    = cluster.GetFileSystem();
            ShortCircuitCache     cache = fs.GetClient().GetClientContext().GetShortCircuitCache(
                );

            cache.GetDfsClientShmManager().Visit(new _Visitor_423());
            // The ClientShmManager starts off empty
            DomainPeer      peer     = GetDomainPeerToDn(conf);
            MutableBoolean  usedPeer = new MutableBoolean(false);
            ExtendedBlockId blockId  = new ExtendedBlockId(123, "xyz");
            DatanodeInfo    datanode = new DatanodeInfo(cluster.GetDataNodes()[0].GetDatanodeId(
                                                            ));

            // Allocating the first shm slot requires using up a peer.
            ShortCircuitShm.Slot slot = cache.AllocShmSlot(datanode, peer, usedPeer, blockId,
                                                           "testAllocShm_client");
            NUnit.Framework.Assert.IsNotNull(slot);
            NUnit.Framework.Assert.IsTrue(usedPeer.BooleanValue());
            cache.GetDfsClientShmManager().Visit(new _Visitor_441(datanode));
            // The ClientShmManager starts off empty
            cache.ScheduleSlotReleaser(slot);
            // Wait for the slot to be released, and the shared memory area to be
            // closed.  Since we didn't register this shared memory segment on the
            // server, it will also be a test of how well the server deals with
            // bogus client behavior.
            GenericTestUtils.WaitFor(new _Supplier_458(cache, datanode), 10, 60000);
            cluster.Shutdown();
            sockDir.Close();
        }
 /// <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);
 }