예제 #1
0
 /// <summary>
 /// Iterate over all the storage directories, checking if it should be
 /// formatted.
 /// </summary>
 /// <remarks>
 /// Iterate over all the storage directories, checking if it should be
 /// formatted. Format the storage if necessary and allowed by the user.
 /// </remarks>
 /// <returns>True if formatting is processed</returns>
 /// <exception cref="System.IO.IOException"/>
 private bool Format(NNStorage storage, NamespaceInfo nsInfo)
 {
     // Check with the user before blowing away data.
     if (!Storage.ConfirmFormat(storage.DirIterable(null), force, interactive))
     {
         storage.Close();
         return(false);
     }
     else
     {
         // Format the storage (writes VERSION file)
         storage.Format(nsInfo);
         return(true);
     }
 }
예제 #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestCancelSaveNamespace()
        {
            Configuration conf = GetConf();

            NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode);
            DFSTestUtil.FormatNameNode(conf);
            FSNamesystem fsn = FSNamesystem.LoadFromDisk(conf);
            // Replace the FSImage with a spy
            FSImage   image   = fsn.GetFSImage();
            NNStorage storage = image.GetStorage();

            storage.Close();
            // unlock any directories that FSNamesystem's initialization may have locked
            storage.SetStorageDirectories(FSNamesystem.GetNamespaceDirs(conf), FSNamesystem.GetNamespaceEditsDirs
                                              (conf));
            FSNamesystem spyFsn   = Org.Mockito.Mockito.Spy(fsn);
            FSNamesystem finalFsn = spyFsn;

            GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(Log);
            BlockIdManager bid = Org.Mockito.Mockito.Spy(spyFsn.GetBlockIdManager());

            Whitebox.SetInternalState(finalFsn, "blockIdManager", bid);
            Org.Mockito.Mockito.DoAnswer(delayer).When(bid).GetGenerationStampV2();
            ExecutorService pool = Executors.NewFixedThreadPool(2);

            try
            {
                DoAnEdit(fsn, 1);
                Canceler canceler = new Canceler();
                // Save namespace
                fsn.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                try
                {
                    Future <Void> saverFuture = pool.Submit(new _Callable_561(image, finalFsn, canceler
                                                                              ));
                    // Wait until saveNamespace calls getGenerationStamp
                    delayer.WaitForCall();
                    // then cancel the saveNamespace
                    Future <Void> cancelFuture = pool.Submit(new _Callable_572(canceler));
                    // give the cancel call time to run
                    Sharpen.Thread.Sleep(500);
                    // allow saveNamespace to proceed - it should check the cancel flag after
                    // this point and throw an exception
                    delayer.Proceed();
                    cancelFuture.Get();
                    saverFuture.Get();
                    NUnit.Framework.Assert.Fail("saveNamespace did not fail even though cancelled!");
                }
                catch (Exception t)
                {
                    GenericTestUtils.AssertExceptionContains("SaveNamespaceCancelledException", t);
                }
                Log.Info("Successfully cancelled a saveNamespace");
                // Check that we have only the original image and not any
                // cruft left over from half-finished images
                FSImageTestUtil.LogStorageContents(Log, storage);
                foreach (Storage.StorageDirectory sd in storage.DirIterable(null))
                {
                    FilePath curDir = sd.GetCurrentDir();
                    GenericTestUtils.AssertGlobEquals(curDir, "fsimage_.*", NNStorage.GetImageFileName
                                                          (0), NNStorage.GetImageFileName(0) + MD5FileUtils.Md5Suffix);
                }
            }
            finally
            {
                fsn.Close();
            }
        }
예제 #3
0
        /// <summary>Injects a failure on all storage directories while saving namespace.</summary>
        /// <param name="restoreStorageAfterFailure">
        /// if true, will try to save again after
        /// clearing the failure injection
        /// </param>
        /// <exception cref="System.Exception"/>
        public virtual void DoTestFailedSaveNamespace(bool restoreStorageAfterFailure)
        {
            Configuration conf = GetConf();

            NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode);
            DFSTestUtil.FormatNameNode(conf);
            FSNamesystem fsn = FSNamesystem.LoadFromDisk(conf);
            // Replace the FSImage with a spy
            FSImage   originalImage = fsn.GetFSImage();
            NNStorage storage       = originalImage.GetStorage();

            storage.Close();
            // unlock any directories that FSNamesystem's initialization may have locked
            NNStorage spyStorage = Org.Mockito.Mockito.Spy(storage);

            originalImage.storage = spyStorage;
            FSImage spyImage = Org.Mockito.Mockito.Spy(originalImage);

            Whitebox.SetInternalState(fsn, "fsImage", spyImage);
            spyImage.storage.SetStorageDirectories(FSNamesystem.GetNamespaceDirs(conf), FSNamesystem
                                                   .GetNamespaceEditsDirs(conf));
            Org.Mockito.Mockito.DoThrow(new IOException("Injected fault: saveFSImage")).When(
                spyImage).SaveFSImage((SaveNamespaceContext)Matchers.AnyObject(), (Storage.StorageDirectory
                                                                                   )Matchers.AnyObject(), (NNStorage.NameNodeFile)Matchers.AnyObject());
            try
            {
                DoAnEdit(fsn, 1);
                // Save namespace
                fsn.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                try
                {
                    fsn.SaveNamespace();
                    NUnit.Framework.Assert.Fail("saveNamespace did not fail even when all directories failed!"
                                                );
                }
                catch (IOException ioe)
                {
                    Log.Info("Got expected exception", ioe);
                }
                // Ensure that, if storage dirs come back online, things work again.
                if (restoreStorageAfterFailure)
                {
                    Org.Mockito.Mockito.Reset(spyImage);
                    spyStorage.SetRestoreFailedStorage(true);
                    fsn.SaveNamespace();
                    CheckEditExists(fsn, 1);
                }
                // Now shut down and restart the NN
                originalImage.Close();
                fsn.Close();
                fsn = null;
                // Start a new namesystem, which should be able to recover
                // the namespace from the previous incarnation.
                fsn = FSNamesystem.LoadFromDisk(conf);
                // Make sure the image loaded including our edits.
                CheckEditExists(fsn, 1);
            }
            finally
            {
                if (fsn != null)
                {
                    fsn.Close();
                }
            }
        }