Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestRemoveVolumes()
        {
            // Feed FsDataset with block metadata.
            int NumBlocks = 100;

            for (int i = 0; i < NumBlocks; i++)
            {
                string        bpid = BlockPoolIds[NumBlocks % BlockPoolIds.Length];
                ExtendedBlock eb   = new ExtendedBlock(bpid, i);
                using (ReplicaHandler replica = dataset.CreateRbw(StorageType.Default, eb, false))
                {
                }
            }
            string[] dataDirs                      = conf.Get(DFSConfigKeys.DfsDatanodeDataDirKey).Split(",");
            string   volumePathToRemove            = dataDirs[0];
            ICollection <FilePath> volumesToRemove = new HashSet <FilePath>();

            volumesToRemove.AddItem(StorageLocation.Parse(volumePathToRemove).GetFile());
            dataset.RemoveVolumes(volumesToRemove, true);
            int expectedNumVolumes = dataDirs.Length - 1;

            NUnit.Framework.Assert.AreEqual("The volume has been removed from the volumeList."
                                            , expectedNumVolumes, dataset.GetVolumes().Count);
            NUnit.Framework.Assert.AreEqual("The volume has been removed from the storageMap."
                                            , expectedNumVolumes, dataset.storageMap.Count);
            try
            {
                dataset.asyncDiskService.Execute(volumesToRemove.GetEnumerator().Next(), new _Runnable_220
                                                     ());
                NUnit.Framework.Assert.Fail("Expect RuntimeException: the volume has been removed from the "
                                            + "AsyncDiskService.");
            }
            catch (RuntimeException e)
            {
                GenericTestUtils.AssertExceptionContains("Cannot find root", e);
            }
            int totalNumReplicas = 0;

            foreach (string bpid_1 in dataset.volumeMap.GetBlockPoolList())
            {
                totalNumReplicas += dataset.volumeMap.Size(bpid_1);
            }
            NUnit.Framework.Assert.AreEqual("The replica infos on this volume has been removed from the "
                                            + "volumeMap.", NumBlocks / NumInitVolumes, totalNumReplicas);
        }
Пример #2
0
 /// <exception cref="System.IO.IOException"/>
 private void TestWriteToRbw(FsDatasetImpl dataSet, ExtendedBlock[] blocks)
 {
     try
     {
         dataSet.RecoverRbw(blocks[Finalized], blocks[Finalized].GetGenerationStamp() + 1,
                            0L, blocks[Finalized].GetNumBytes());
         NUnit.Framework.Assert.Fail("Should not have recovered a finalized replica " + blocks
                                     [Finalized]);
     }
     catch (ReplicaNotFoundException e)
     {
         NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica
                                                            ));
     }
     try
     {
         dataSet.CreateRbw(StorageType.Default, blocks[Finalized], false);
         NUnit.Framework.Assert.Fail("Should not have created a replica that's already " +
                                     "finalized " + blocks[Finalized]);
     }
     catch (ReplicaAlreadyExistsException)
     {
     }
     try
     {
         dataSet.RecoverRbw(blocks[Temporary], blocks[Temporary].GetGenerationStamp() + 1,
                            0L, blocks[Temporary].GetNumBytes());
         NUnit.Framework.Assert.Fail("Should not have recovered a temporary replica " + blocks
                                     [Temporary]);
     }
     catch (ReplicaNotFoundException e)
     {
         NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica
                                                            ));
     }
     try
     {
         dataSet.CreateRbw(StorageType.Default, blocks[Temporary], false);
         NUnit.Framework.Assert.Fail("Should not have created a replica that had created as "
                                     + "temporary " + blocks[Temporary]);
     }
     catch (ReplicaAlreadyExistsException)
     {
     }
     dataSet.RecoverRbw(blocks[Rbw], blocks[Rbw].GetGenerationStamp() + 1, 0L, blocks[
                            Rbw].GetNumBytes());
     // expect to be successful
     try
     {
         dataSet.CreateRbw(StorageType.Default, blocks[Rbw], false);
         NUnit.Framework.Assert.Fail("Should not have created a replica that had created as RBW "
                                     + blocks[Rbw]);
     }
     catch (ReplicaAlreadyExistsException)
     {
     }
     try
     {
         dataSet.RecoverRbw(blocks[Rwr], blocks[Rwr].GetGenerationStamp() + 1, 0L, blocks[
                                Rwr].GetNumBytes());
         NUnit.Framework.Assert.Fail("Should not have recovered a RWR replica " + blocks[Rwr
                                     ]);
     }
     catch (ReplicaNotFoundException e)
     {
         NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica
                                                            ));
     }
     try
     {
         dataSet.CreateRbw(StorageType.Default, blocks[Rwr], false);
         NUnit.Framework.Assert.Fail("Should not have created a replica that was waiting to be "
                                     + "recovered " + blocks[Rwr]);
     }
     catch (ReplicaAlreadyExistsException)
     {
     }
     try
     {
         dataSet.RecoverRbw(blocks[Rur], blocks[Rur].GetGenerationStamp() + 1, 0L, blocks[
                                Rur].GetNumBytes());
         NUnit.Framework.Assert.Fail("Should not have recovered a RUR replica " + blocks[Rur
                                     ]);
     }
     catch (ReplicaNotFoundException e)
     {
         NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica
                                                            ));
     }
     try
     {
         dataSet.CreateRbw(StorageType.Default, blocks[Rur], false);
         NUnit.Framework.Assert.Fail("Should not have created a replica that was under recovery "
                                     + blocks[Rur]);
     }
     catch (ReplicaAlreadyExistsException)
     {
     }
     try
     {
         dataSet.RecoverRbw(blocks[NonExistent], blocks[NonExistent].GetGenerationStamp()
                            + 1, 0L, blocks[NonExistent].GetNumBytes());
         NUnit.Framework.Assert.Fail("Cannot recover a non-existent replica " + blocks[NonExistent
                                     ]);
     }
     catch (ReplicaNotFoundException e)
     {
         NUnit.Framework.Assert.IsTrue(e.Message.Contains(ReplicaNotFoundException.NonExistentReplica
                                                          ));
     }
     dataSet.CreateRbw(StorageType.Default, blocks[NonExistent], false);
 }