Exemplo n.º 1
0
        public virtual void TestAddStorage()
        {
            BlockInfoContiguous blockInfo = new BlockInfoContiguous((short)3);
            DatanodeStorageInfo storage   = DFSTestUtil.CreateDatanodeStorageInfo("storageID",
                                                                                  "127.0.0.1");
            bool added = blockInfo.AddStorage(storage);

            NUnit.Framework.Assert.IsTrue(added);
            NUnit.Framework.Assert.AreEqual(storage, blockInfo.GetStorageInfo(0));
        }
        public virtual void TestInitializeBlockRecovery()
        {
            DatanodeStorageInfo s1  = DFSTestUtil.CreateDatanodeStorageInfo("10.10.1.1", "s1");
            DatanodeDescriptor  dd1 = s1.GetDatanodeDescriptor();
            DatanodeStorageInfo s2  = DFSTestUtil.CreateDatanodeStorageInfo("10.10.1.2", "s2");
            DatanodeDescriptor  dd2 = s2.GetDatanodeDescriptor();
            DatanodeStorageInfo s3  = DFSTestUtil.CreateDatanodeStorageInfo("10.10.1.3", "s3");
            DatanodeDescriptor  dd3 = s3.GetDatanodeDescriptor();

            dd1.isAlive = dd2.isAlive = dd3.isAlive = true;
            BlockInfoContiguousUnderConstruction blockInfo = new BlockInfoContiguousUnderConstruction
                                                                 (new Block(0, 0, GenerationStamp.LastReservedStamp), (short)3, HdfsServerConstants.BlockUCState
                                                                 .UnderConstruction, new DatanodeStorageInfo[] { s1, s2, s3 });

            // Recovery attempt #1.
            DFSTestUtil.ResetLastUpdatesWithOffset(dd1, -3 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd2, -1 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd3, -2 * 1000);
            blockInfo.InitializeBlockRecovery(1);
            BlockInfoContiguousUnderConstruction[] blockInfoRecovery = dd2.GetLeaseRecoveryCommand
                                                                           (1);
            NUnit.Framework.Assert.AreEqual(blockInfoRecovery[0], blockInfo);
            // Recovery attempt #2.
            DFSTestUtil.ResetLastUpdatesWithOffset(dd1, -2 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd2, -1 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd3, -3 * 1000);
            blockInfo.InitializeBlockRecovery(2);
            blockInfoRecovery = dd1.GetLeaseRecoveryCommand(1);
            NUnit.Framework.Assert.AreEqual(blockInfoRecovery[0], blockInfo);
            // Recovery attempt #3.
            DFSTestUtil.ResetLastUpdatesWithOffset(dd1, -2 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd2, -1 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd3, -3 * 1000);
            blockInfo.InitializeBlockRecovery(3);
            blockInfoRecovery = dd3.GetLeaseRecoveryCommand(1);
            NUnit.Framework.Assert.AreEqual(blockInfoRecovery[0], blockInfo);
            // Recovery attempt #4.
            // Reset everything. And again pick DN with most recent heart beat.
            DFSTestUtil.ResetLastUpdatesWithOffset(dd1, -2 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd2, -1 * 1000);
            DFSTestUtil.ResetLastUpdatesWithOffset(dd3, 0);
            blockInfo.InitializeBlockRecovery(3);
            blockInfoRecovery = dd3.GetLeaseRecoveryCommand(1);
            NUnit.Framework.Assert.AreEqual(blockInfoRecovery[0], blockInfo);
        }
Exemplo n.º 3
0
        public virtual void TestReplaceStorage()
        {
            // Create two dummy storages.
            DatanodeStorageInfo storage1 = DFSTestUtil.CreateDatanodeStorageInfo("storageID1"
                                                                                 , "127.0.0.1");
            DatanodeStorageInfo storage2 = new DatanodeStorageInfo(storage1.GetDatanodeDescriptor
                                                                       (), new DatanodeStorage("storageID2"));
            int NumBlocks = 10;

            BlockInfoContiguous[] blockInfos = new BlockInfoContiguous[NumBlocks];
            // Create a few dummy blocks and add them to the first storage.
            for (int i = 0; i < NumBlocks; ++i)
            {
                blockInfos[i] = new BlockInfoContiguous((short)3);
                storage1.AddBlock(blockInfos[i]);
            }
            // Try to move one of the blocks to a different storage.
            bool added = storage2.AddBlock(blockInfos[NumBlocks / 2]) == DatanodeStorageInfo.AddBlockResult
                         .Added;

            Assert.AssertThat(added, IS.Is(false));
            Assert.AssertThat(blockInfos[NumBlocks / 2].GetStorageInfo(0), IS.Is(storage2));
        }
Exemplo n.º 4
0
        public virtual void TestBlockListMoveToHead()
        {
            Log.Info("BlockInfo moveToHead tests...");
            int MaxBlocks = 10;
            DatanodeStorageInfo         dd            = DFSTestUtil.CreateDatanodeStorageInfo("s1", "1.1.1.1");
            AList <Block>               blockList     = new AList <Block>(MaxBlocks);
            AList <BlockInfoContiguous> blockInfoList = new AList <BlockInfoContiguous>();
            int headIndex;
            int curIndex;

            Log.Info("Building block list...");
            for (int i = 0; i < MaxBlocks; i++)
            {
                blockList.AddItem(new Block(i, 0, GenerationStamp.LastReservedStamp));
                blockInfoList.AddItem(new BlockInfoContiguous(blockList[i], (short)3));
                dd.AddBlock(blockInfoList[i]);
                // index of the datanode should be 0
                NUnit.Framework.Assert.AreEqual("Find datanode should be 0", 0, blockInfoList[i].
                                                FindStorageInfo(dd));
            }
            // list length should be equal to the number of blocks we inserted
            Log.Info("Checking list length...");
            NUnit.Framework.Assert.AreEqual("Length should be MAX_BLOCK", MaxBlocks, dd.NumBlocks
                                                ());
            IEnumerator <BlockInfoContiguous> it = dd.GetBlockIterator();
            int len = 0;

            while (it.HasNext())
            {
                it.Next();
                len++;
            }
            NUnit.Framework.Assert.AreEqual("There should be MAX_BLOCK blockInfo's", MaxBlocks
                                            , len);
            headIndex = dd.GetBlockListHeadForTesting().FindStorageInfo(dd);
            Log.Info("Moving each block to the head of the list...");
            for (int i_1 = 0; i_1 < MaxBlocks; i_1++)
            {
                curIndex  = blockInfoList[i_1].FindStorageInfo(dd);
                headIndex = dd.MoveBlockToHead(blockInfoList[i_1], curIndex, headIndex);
                // the moved element must be at the head of the list
                NUnit.Framework.Assert.AreEqual("Block should be at the head of the list now.", blockInfoList
                                                [i_1], dd.GetBlockListHeadForTesting());
            }
            // move head of the list to the head - this should not change the list
            Log.Info("Moving head to the head...");
            BlockInfoContiguous temp = dd.GetBlockListHeadForTesting();

            curIndex  = 0;
            headIndex = 0;
            dd.MoveBlockToHead(temp, curIndex, headIndex);
            NUnit.Framework.Assert.AreEqual("Moving head to the head of the list shopuld not change the list"
                                            , temp, dd.GetBlockListHeadForTesting());
            // check all elements of the list against the original blockInfoList
            Log.Info("Checking elements of the list...");
            temp = dd.GetBlockListHeadForTesting();
            NUnit.Framework.Assert.IsNotNull("Head should not be null", temp);
            int c = MaxBlocks - 1;

            while (temp != null)
            {
                NUnit.Framework.Assert.AreEqual("Expected element is not on the list", blockInfoList
                                                [c--], temp);
                temp = temp.GetNext(0);
            }
            Log.Info("Moving random blocks to the head of the list...");
            headIndex = dd.GetBlockListHeadForTesting().FindStorageInfo(dd);
            Random rand = new Random();

            for (int i_2 = 0; i_2 < MaxBlocks; i_2++)
            {
                int j = rand.Next(MaxBlocks);
                curIndex  = blockInfoList[j].FindStorageInfo(dd);
                headIndex = dd.MoveBlockToHead(blockInfoList[j], curIndex, headIndex);
                // the moved element must be at the head of the list
                NUnit.Framework.Assert.AreEqual("Block should be at the head of the list now.", blockInfoList
                                                [j], dd.GetBlockListHeadForTesting());
            }
        }