Пример #1
0
 /// <summary>Evict and close sockets older than expiry period from the cache.</summary>
 private void EvictExpired(long expiryPeriod)
 {
     lock (this)
     {
         while (multimap.Size() != 0)
         {
             IEnumerator <KeyValuePair <PeerCache.Key, PeerCache.Value> > iter = multimap.Entries
                                                                                     ().GetEnumerator();
             KeyValuePair <PeerCache.Key, PeerCache.Value> entry = iter.Next();
             // if oldest socket expired, remove it
             if (entry == null || Time.MonotonicNow() - entry.Value.GetTime() < expiryPeriod)
             {
                 break;
             }
             IOUtils.Cleanup(Log, entry.Value.GetPeer());
             iter.Remove();
         }
     }
 }
Пример #2
0
        private DatanodeStorageInfo[] ScheduleSingleReplication(Block block)
        {
            // list for priority 1
            IList <Block> list_p1 = new AList <Block>();

            list_p1.AddItem(block);
            // list of lists for each priority
            IList <IList <Block> > list_all = new AList <IList <Block> >();

            list_all.AddItem(new AList <Block>());
            // for priority 0
            list_all.AddItem(list_p1);
            // for priority 1
            NUnit.Framework.Assert.AreEqual("Block not initially pending replication", 0, bm.
                                            pendingReplications.GetNumReplicas(block));
            NUnit.Framework.Assert.AreEqual("computeReplicationWork should indicate replication is needed"
                                            , 1, bm.ComputeReplicationWorkForBlocks(list_all));
            NUnit.Framework.Assert.IsTrue("replication is pending after work is computed", bm
                                          .pendingReplications.GetNumReplicas(block) > 0);
            LinkedListMultimap <DatanodeStorageInfo, DatanodeDescriptor.BlockTargetPair> repls
                = GetAllPendingReplications();

            NUnit.Framework.Assert.AreEqual(1, repls.Size());
            KeyValuePair <DatanodeStorageInfo, DatanodeDescriptor.BlockTargetPair> repl = repls
                                                                                          .Entries().GetEnumerator().Next();

            DatanodeStorageInfo[] targets  = repl.Value.targets;
            DatanodeStorageInfo[] pipeline = new DatanodeStorageInfo[1 + targets.Length];
            pipeline[0] = repl.Key;
            System.Array.Copy(targets, 0, pipeline, 1, targets.Length);
            return(pipeline);
        }