예제 #1
0
        public virtual void TestMultipleLists()
        {
            DatanodeDescriptor[] datanodes = new DatanodeDescriptor[] { new DatanodeDescriptor
                                                                            (new DatanodeID("127.0.0.1", "localhost", "abcd", 5000, 5001, 5002, 5003)), new
                                                                        DatanodeDescriptor(new DatanodeID("127.0.1.1", "localhost", "efgh", 6000, 6001,
                                                                                                          6002, 6003)) };
            DatanodeDescriptor.CachedBlocksList[] lists = new DatanodeDescriptor.CachedBlocksList
                                                          [] { datanodes[0].GetPendingCached(), datanodes[0].GetCached(), datanodes[1].GetPendingCached
                                                                   (), datanodes[1].GetCached(), datanodes[1].GetPendingUncached() };
            int NumBlocks = 8000;

            CachedBlock[] blocks = new CachedBlock[NumBlocks];
            for (int i = 0; i < NumBlocks; i++)
            {
                blocks[i] = new CachedBlock(i, (short)i, true);
            }
            Random r = new Random(654);

            foreach (DatanodeDescriptor.CachedBlocksList list in lists)
            {
                TestAddElementsToList(list, blocks);
            }
            foreach (DatanodeDescriptor.CachedBlocksList list_1 in lists)
            {
                TestRemoveElementsFromList(r, list_1, blocks);
            }
        }
예제 #2
0
        /// <summary>DatanodeDescriptor constructor</summary>
        /// <param name="nodeID">id of the data node</param>
        public DatanodeDescriptor(DatanodeID nodeID)
            : base(nodeID)
        {
            decommissioningStatus = new DatanodeDescriptor.DecommissioningStatus(this);
            pendingCached         = new DatanodeDescriptor.CachedBlocksList(this, DatanodeDescriptor.CachedBlocksList.Type
                                                                            .PendingCached);
            cached = new DatanodeDescriptor.CachedBlocksList(this, DatanodeDescriptor.CachedBlocksList.Type
                                                             .Cached);
            pendingUncached = new DatanodeDescriptor.CachedBlocksList(this, DatanodeDescriptor.CachedBlocksList.Type
                                                                      .PendingUncached);
            // isAlive == heartbeats.contains(this)
            // This is an optimization, because contains takes O(n) time on Arraylist
            // A system administrator can tune the balancer bandwidth parameter
            // (dfs.balance.bandwidthPerSec) dynamically by calling
            // "dfsadmin -setBalanacerBandwidth <newbandwidth>", at which point the
            // following 'bandwidth' variable gets updated with the new value for each
            // node. Once the heartbeat command is issued to update the value on the
            // specified datanode, this value will be set back to 0.

            /* Variables for maintaining number of blocks scheduled to be written to
             * this storage. This count is approximate and might be slightly bigger
             * in case of errors (e.g. datanode does not report if an error occurs
             * while writing the block).
             */
            //10min
            // The number of replication work pending before targets are determined
            // HB processing can use it to tell if it is the first HB since DN restarted
            UpdateHeartbeatState(StorageReport.EmptyArray, 0L, 0L, 0, 0, null);
        }
예제 #3
0
 private void TestAddElementsToList(DatanodeDescriptor.CachedBlocksList list, CachedBlock
                                    [] blocks)
 {
     NUnit.Framework.Assert.IsTrue("expected list to start off empty.", !list.GetEnumerator
                                       ().HasNext());
     foreach (CachedBlock block in blocks)
     {
         NUnit.Framework.Assert.IsTrue(list.AddItem(block));
     }
 }
예제 #4
0
 /// <summary>DatanodeDescriptor constructor</summary>
 /// <param name="nodeID">id of the data node</param>
 /// <param name="networkLocation">location of the data node in network</param>
 public DatanodeDescriptor(DatanodeID nodeID, string networkLocation)
     : base(nodeID, networkLocation)
 {
     decommissioningStatus = new DatanodeDescriptor.DecommissioningStatus(this);
     pendingCached         = new DatanodeDescriptor.CachedBlocksList(this, DatanodeDescriptor.CachedBlocksList.Type
                                                                     .PendingCached);
     cached = new DatanodeDescriptor.CachedBlocksList(this, DatanodeDescriptor.CachedBlocksList.Type
                                                      .Cached);
     pendingUncached = new DatanodeDescriptor.CachedBlocksList(this, DatanodeDescriptor.CachedBlocksList.Type
                                                               .PendingUncached);
     UpdateHeartbeatState(StorageReport.EmptyArray, 0L, 0L, 0, 0, null);
 }
예제 #5
0
        private void TestRemoveElementsFromList(Random r, DatanodeDescriptor.CachedBlocksList
                                                list, CachedBlock[] blocks)
        {
            int i = 0;

            for (IEnumerator <CachedBlock> iter = list.GetEnumerator(); iter.HasNext();)
            {
                NUnit.Framework.Assert.AreEqual(blocks[i], iter.Next());
                i++;
            }
            if (r.NextBoolean())
            {
                Log.Info("Removing via iterator");
                for (IEnumerator <CachedBlock> iter_1 = list.GetEnumerator(); iter_1.HasNext();)
                {
                    iter_1.Next();
                    iter_1.Remove();
                }
            }
            else
            {
                Log.Info("Removing in pseudo-random order");
                CachedBlock[] remainingBlocks = Arrays.CopyOf(blocks, blocks.Length);
                for (int removed = 0; removed < remainingBlocks.Length;)
                {
                    int toRemove = r.Next(remainingBlocks.Length);
                    if (remainingBlocks[toRemove] != null)
                    {
                        NUnit.Framework.Assert.IsTrue(list.Remove(remainingBlocks[toRemove]));
                        remainingBlocks[toRemove] = null;
                        removed++;
                    }
                }
            }
            NUnit.Framework.Assert.IsTrue("expected list to be empty after everything " + "was removed."
                                          , !list.GetEnumerator().HasNext());
        }