Beispiel #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestSetrepIncWithUnderReplicatedBlocks()
        {
            // 1 min timeout
            Configuration  conf = new HdfsConfiguration();
            short          ReplicationFactor = 2;
            string         FileName          = "/testFile";
            Path           FilePath          = new Path(FileName);
            MiniDFSCluster cluster           = new MiniDFSCluster.Builder(conf).NumDataNodes(ReplicationFactor
                                                                                             + 1).Build();

            try
            {
                // create a file with one block with a replication factor of 2
                FileSystem fs = cluster.GetFileSystem();
                DFSTestUtil.CreateFile(fs, FilePath, 1L, ReplicationFactor, 1L);
                DFSTestUtil.WaitReplication(fs, FilePath, ReplicationFactor);
                // remove one replica from the blocksMap so block becomes under-replicated
                // but the block does not get put into the under-replicated blocks queue
                BlockManager       bm = cluster.GetNamesystem().GetBlockManager();
                ExtendedBlock      b  = DFSTestUtil.GetFirstBlock(fs, FilePath);
                DatanodeDescriptor dn = bm.blocksMap.GetStorages(b.GetLocalBlock()).GetEnumerator
                                            ().Next().GetDatanodeDescriptor();
                bm.AddToInvalidates(b.GetLocalBlock(), dn);
                Sharpen.Thread.Sleep(5000);
                bm.blocksMap.RemoveNode(b.GetLocalBlock(), dn);
                // increment this file's replication factor
                FsShell shell = new FsShell(conf);
                NUnit.Framework.Assert.AreEqual(0, shell.Run(new string[] { "-setrep", "-w", Sharpen.Extensions.ToString
                                                                                (1 + ReplicationFactor), FileName }));
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Test if
        /// <see cref="BlockManager.ComputeInvalidateWork(int)"/>
        /// can schedule invalidate work correctly
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestCompInvalidate()
        {
            int blockInvalidateLimit = bm.GetDatanodeManager().blockInvalidateLimit;

            namesystem.WriteLock();
            try
            {
                for (int i = 0; i < nodes.Length; i++)
                {
                    for (int j = 0; j < 3 * blockInvalidateLimit + 1; j++)
                    {
                        Block block = new Block(i * (blockInvalidateLimit + 1) + j, 0, GenerationStamp.LastReservedStamp
                                                );
                        bm.AddToInvalidates(block, nodes[i]);
                    }
                }
                NUnit.Framework.Assert.AreEqual(blockInvalidateLimit * NumOfDatanodes, bm.ComputeInvalidateWork
                                                    (NumOfDatanodes + 1));
                NUnit.Framework.Assert.AreEqual(blockInvalidateLimit * NumOfDatanodes, bm.ComputeInvalidateWork
                                                    (NumOfDatanodes));
                NUnit.Framework.Assert.AreEqual(blockInvalidateLimit * (NumOfDatanodes - 1), bm.ComputeInvalidateWork
                                                    (NumOfDatanodes - 1));
                int workCount = bm.ComputeInvalidateWork(1);
                if (workCount == 1)
                {
                    NUnit.Framework.Assert.AreEqual(blockInvalidateLimit + 1, bm.ComputeInvalidateWork
                                                        (2));
                }
                else
                {
                    NUnit.Framework.Assert.AreEqual(workCount, blockInvalidateLimit);
                    NUnit.Framework.Assert.AreEqual(2, bm.ComputeInvalidateWork(2));
                }
            }
            finally
            {
                namesystem.WriteUnlock();
            }
        }