Exemple #1
0
        public virtual void TestLocatedBlocks2Locations()
        {
            DatanodeInfo d = DFSTestUtil.GetLocalDatanodeInfo();

            DatanodeInfo[] ds = new DatanodeInfo[1];
            ds[0] = d;
            // ok
            ExtendedBlock b1 = new ExtendedBlock("bpid", 1, 1, 1);
            LocatedBlock  l1 = new LocatedBlock(b1, ds, 0, false);
            // corrupt
            ExtendedBlock        b2  = new ExtendedBlock("bpid", 2, 1, 1);
            LocatedBlock         l2  = new LocatedBlock(b2, ds, 0, true);
            IList <LocatedBlock> ls  = Arrays.AsList(l1, l2);
            LocatedBlocks        lbs = new LocatedBlocks(10, false, ls, l2, true, null);

            BlockLocation[] bs = DFSUtil.LocatedBlocks2Locations(lbs);
            NUnit.Framework.Assert.IsTrue("expected 2 blocks but got " + bs.Length, bs.Length
                                          == 2);
            int corruptCount = 0;

            foreach (BlockLocation b in bs)
            {
                if (b.IsCorrupt())
                {
                    corruptCount++;
                }
            }
            NUnit.Framework.Assert.IsTrue("expected 1 corrupt files but got " + corruptCount,
                                          corruptCount == 1);
            // test an empty location
            bs = DFSUtil.LocatedBlocks2Locations(new LocatedBlocks());
            NUnit.Framework.Assert.AreEqual(0, bs.Length);
        }
Exemple #2
0
        public virtual void TestConvertBlockRecoveryCommand()
        {
            DatanodeInfo di1 = DFSTestUtil.GetLocalDatanodeInfo();
            DatanodeInfo di2 = DFSTestUtil.GetLocalDatanodeInfo();

            DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 };
            IList <BlockRecoveryCommand.RecoveringBlock> blks = ImmutableList.Of(new BlockRecoveryCommand.RecoveringBlock
                                                                                     (GetExtendedBlock(1), dnInfo, 3), new BlockRecoveryCommand.RecoveringBlock(GetExtendedBlock
                                                                                                                                                                    (2), dnInfo, 3));
            BlockRecoveryCommand cmd = new BlockRecoveryCommand(blks);

            DatanodeProtocolProtos.BlockRecoveryCommandProto proto = PBHelper.Convert(cmd);
            NUnit.Framework.Assert.AreEqual(1, proto.GetBlocks(0).GetBlock().GetB().GetBlockId
                                                ());
            NUnit.Framework.Assert.AreEqual(2, proto.GetBlocks(1).GetBlock().GetB().GetBlockId
                                                ());
            BlockRecoveryCommand cmd2 = PBHelper.Convert(proto);
            IList <BlockRecoveryCommand.RecoveringBlock> cmd2Blks = Lists.NewArrayList(cmd2.GetRecoveringBlocks
                                                                                           ());

            NUnit.Framework.Assert.AreEqual(blks[0].GetBlock(), cmd2Blks[0].GetBlock());
            NUnit.Framework.Assert.AreEqual(blks[1].GetBlock(), cmd2Blks[1].GetBlock());
            NUnit.Framework.Assert.AreEqual(Joiner.On(",").Join(blks), Joiner.On(",").Join(cmd2Blks
                                                                                           ));
            NUnit.Framework.Assert.AreEqual(cmd.ToString(), cmd2.ToString());
        }
Exemple #3
0
        public virtual void TestDefaultPolicy()
        {
            Configuration            conf = new HdfsConfiguration();
            ReplaceDatanodeOnFailure p    = ReplaceDatanodeOnFailure.Get(conf);

            DatanodeInfo[]   infos     = new DatanodeInfo[5];
            DatanodeInfo[][] datanodes = new DatanodeInfo[infos.Length + 1][];
            datanodes[0] = new DatanodeInfo[0];
            for (int i = 0; i < infos.Length;)
            {
                infos[i] = DFSTestUtil.GetLocalDatanodeInfo(50020 + i);
                i++;
                datanodes[i] = new DatanodeInfo[i];
                System.Array.Copy(infos, 0, datanodes[i], 0, datanodes[i].Length);
            }
            bool[] isAppend   = new bool[] { true, true, false, false };
            bool[] isHflushed = new bool[] { true, false, true, false };
            for (short replication = 1; replication <= infos.Length; replication++)
            {
                for (int nExistings = 0; nExistings < datanodes.Length; nExistings++)
                {
                    DatanodeInfo[] existings = datanodes[nExistings];
                    NUnit.Framework.Assert.AreEqual(nExistings, existings.Length);
                    for (int i_1 = 0; i_1 < isAppend.Length; i_1++)
                    {
                        for (int j = 0; j < isHflushed.Length; j++)
                        {
                            int  half            = replication / 2;
                            bool enoughReplica   = replication <= nExistings;
                            bool noReplica       = nExistings == 0;
                            bool replicationL3   = replication < 3;
                            bool existingsLEhalf = nExistings <= half;
                            bool isAH            = isAppend[i_1] || isHflushed[j];
                            bool expected;
                            if (enoughReplica || noReplica || replicationL3)
                            {
                                expected = false;
                            }
                            else
                            {
                                expected = isAH || existingsLEhalf;
                            }
                            bool computed = p.Satisfy(replication, existings, isAppend[i_1], isHflushed[j]);
                            try
                            {
                                NUnit.Framework.Assert.AreEqual(expected, computed);
                            }
                            catch (Exception e)
                            {
                                string s = "replication=" + replication + "\nnExistings =" + nExistings + "\nisAppend   ="
                                           + isAppend[i_1] + "\nisHflushed =" + isHflushed[j];
                                throw new RuntimeException(s, e);
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
        public virtual void TestLocatedBlockConstructorWithNullCachedLocs()
        {
            DatanodeInfo d = DFSTestUtil.GetLocalDatanodeInfo();

            DatanodeInfo[] ds = new DatanodeInfo[1];
            ds[0] = d;
            ExtendedBlock b1 = new ExtendedBlock("bpid", 1, 1, 1);
            LocatedBlock  l1 = new LocatedBlock(b1, ds, null, null, 0, false, null);

            DatanodeInfo[] cachedLocs = l1.GetCachedLocations();
            NUnit.Framework.Assert.IsTrue(cachedLocs.Length == 0);
        }
        /// <exception cref="System.IO.IOException"/>
        private ICollection <BlockRecoveryCommand.RecoveringBlock> InitRecoveringBlocks()
        {
            ICollection <BlockRecoveryCommand.RecoveringBlock> blocks = new AList <BlockRecoveryCommand.RecoveringBlock
                                                                                   >(1);
            DatanodeInfo mockOtherDN = DFSTestUtil.GetLocalDatanodeInfo();

            DatanodeInfo[] locs = new DatanodeInfo[] { new DatanodeInfo(dn.GetDNRegistrationForBP
                                                                            (block.GetBlockPoolId())), mockOtherDN };
            BlockRecoveryCommand.RecoveringBlock rBlock = new BlockRecoveryCommand.RecoveringBlock
                                                              (block, locs, RecoveryId);
            blocks.AddItem(rBlock);
            return(blocks);
        }
Exemple #6
0
        private LocatedBlock CreateLocatedBlockNoStorageMedia()
        {
            DatanodeInfo[] dnInfos = new DatanodeInfo[] { DFSTestUtil.GetLocalDatanodeInfo("127.0.0.1"
                                                                                           , "h1", DatanodeInfo.AdminStates.DecommissionInprogress), DFSTestUtil.GetLocalDatanodeInfo
                                                              ("127.0.0.1", "h2", DatanodeInfo.AdminStates.Decommissioned), DFSTestUtil.GetLocalDatanodeInfo
                                                              ("127.0.0.1", "h3", DatanodeInfo.AdminStates.Normal) };
            LocatedBlock lb = new LocatedBlock(new ExtendedBlock("bp12", 12345, 10, 53), dnInfos
                                               , 5, false);

            lb.SetBlockToken(new Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier>
                                 (Sharpen.Runtime.GetBytesForString("identifier"), Sharpen.Runtime.GetBytesForString
                                     ("password"), new Text("kind"), new Text("service")));
            return(lb);
        }
Exemple #7
0
        /// <exception cref="System.IO.IOException"/>
        private void GetBlocksWithException(NamenodeProtocol namenode, DatanodeInfo datanode
                                            , long size)
        {
            bool getException = false;

            try
            {
                namenode.GetBlocks(DFSTestUtil.GetLocalDatanodeInfo(), 2);
            }
            catch (RemoteException e)
            {
                getException = true;
                NUnit.Framework.Assert.IsTrue(e.GetClassName().Contains("HadoopIllegalArgumentException"
                                                                        ));
            }
            NUnit.Framework.Assert.IsTrue(getException);
        }
Exemple #8
0
        private LocatedBlock CreateLocatedBlock()
        {
            DatanodeInfo[] dnInfos = new DatanodeInfo[] { DFSTestUtil.GetLocalDatanodeInfo("127.0.0.1"
                                                                                           , "h1", DatanodeInfo.AdminStates.DecommissionInprogress), DFSTestUtil.GetLocalDatanodeInfo
                                                              ("127.0.0.1", "h2", DatanodeInfo.AdminStates.Decommissioned), DFSTestUtil.GetLocalDatanodeInfo
                                                              ("127.0.0.1", "h3", DatanodeInfo.AdminStates.Normal), DFSTestUtil.GetLocalDatanodeInfo
                                                              ("127.0.0.1", "h4", DatanodeInfo.AdminStates.Normal) };
            string[]      storageIDs = new string[] { "s1", "s2", "s3", "s4" };
            StorageType[] media      = new StorageType[] { StorageType.Disk, StorageType.Ssd, StorageType
                                                           .Disk, StorageType.RamDisk };
            LocatedBlock lb = new LocatedBlock(new ExtendedBlock("bp12", 12345, 10, 53), dnInfos
                                               , storageIDs, media, 5, false, new DatanodeInfo[] {  });

            lb.SetBlockToken(new Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier>
                                 (Sharpen.Runtime.GetBytesForString("identifier"), Sharpen.Runtime.GetBytesForString
                                     ("password"), new Text("kind"), new Text("service")));
            return(lb);
        }
Exemple #9
0
        public virtual void TestConvertRecoveringBlock()
        {
            DatanodeInfo di1 = DFSTestUtil.GetLocalDatanodeInfo();
            DatanodeInfo di2 = DFSTestUtil.GetLocalDatanodeInfo();

            DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 };
            BlockRecoveryCommand.RecoveringBlock b = new BlockRecoveryCommand.RecoveringBlock
                                                         (GetExtendedBlock(), dnInfo, 3);
            HdfsProtos.RecoveringBlockProto      bProto = PBHelper.Convert(b);
            BlockRecoveryCommand.RecoveringBlock b1     = PBHelper.Convert(bProto);
            NUnit.Framework.Assert.AreEqual(b.GetBlock(), b1.GetBlock());
            DatanodeInfo[] dnInfo1 = b1.GetLocations();
            NUnit.Framework.Assert.AreEqual(dnInfo.Length, dnInfo1.Length);
            for (int i = 0; i < dnInfo.Length; i++)
            {
                Compare(dnInfo[0], dnInfo1[0]);
            }
        }
Exemple #10
0
        public virtual void TestConvertBlockCommand()
        {
            Org.Apache.Hadoop.Hdfs.Protocol.Block[] blocks = new Org.Apache.Hadoop.Hdfs.Protocol.Block
                                                             [] { new Org.Apache.Hadoop.Hdfs.Protocol.Block(21), new Org.Apache.Hadoop.Hdfs.Protocol.Block
                                                                      (22) };
            DatanodeInfo[][] dnInfos = new DatanodeInfo[][] { new DatanodeInfo[1], new DatanodeInfo
                                                              [2] };
            dnInfos[0][0] = DFSTestUtil.GetLocalDatanodeInfo();
            dnInfos[1][0] = DFSTestUtil.GetLocalDatanodeInfo();
            dnInfos[1][1] = DFSTestUtil.GetLocalDatanodeInfo();
            string[][] storageIDs = new string[][] { new string[] { "s00" }, new string[] { "s10"
                                                                                            , "s11" } };
            StorageType[][] storageTypes = new StorageType[][] { new StorageType[] { StorageType
                                                                                     .Default }, new StorageType[] { StorageType.Default, StorageType.Default } };
            BlockCommand bc = new BlockCommand(DatanodeProtocol.DnaTransfer, "bp1", blocks, dnInfos
                                               , storageTypes, storageIDs);

            DatanodeProtocolProtos.BlockCommandProto bcProto = PBHelper.Convert(bc);
            BlockCommand bc2 = PBHelper.Convert(bcProto);

            NUnit.Framework.Assert.AreEqual(bc.GetAction(), bc2.GetAction());
            NUnit.Framework.Assert.AreEqual(bc.GetBlocks().Length, bc2.GetBlocks().Length);
            Org.Apache.Hadoop.Hdfs.Protocol.Block[] blocks2 = bc2.GetBlocks();
            for (int i = 0; i < blocks.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(blocks[i], blocks2[i]);
            }
            DatanodeInfo[][] dnInfos2 = bc2.GetTargets();
            NUnit.Framework.Assert.AreEqual(dnInfos.Length, dnInfos2.Length);
            for (int i_1 = 0; i_1 < dnInfos.Length; i_1++)
            {
                DatanodeInfo[] d1 = dnInfos[i_1];
                DatanodeInfo[] d2 = dnInfos2[i_1];
                NUnit.Framework.Assert.AreEqual(d1.Length, d2.Length);
                for (int j = 0; j < d1.Length; j++)
                {
                    Compare(d1[j], d2[j]);
                }
            }
        }