/// <summary>This is called when using bootstrapStandby for HA upgrade.</summary>
        /// <remarks>
        /// This is called when using bootstrapStandby for HA upgrade. The SBN should
        /// also create previous directory so that later when it starts, it understands
        /// that the cluster is in the upgrade state. This function renames the old
        /// current directory to previous.tmp.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        private bool DoPreUpgrade(NNStorage storage, NamespaceInfo nsInfo)
        {
            bool isFormatted = false;
            IDictionary <Storage.StorageDirectory, Storage.StorageState> dataDirStates = new Dictionary
                                                                                         <Storage.StorageDirectory, Storage.StorageState>();

            try
            {
                isFormatted = FSImage.RecoverStorageDirs(HdfsServerConstants.StartupOption.Upgrade
                                                         , storage, dataDirStates);
                if (dataDirStates.Values.Contains(Storage.StorageState.NotFormatted))
                {
                    // recoverStorageDirs returns true if there is a formatted directory
                    isFormatted = false;
                    System.Console.Error.WriteLine("The original storage directory is not formatted."
                                                   );
                }
            }
            catch (InconsistentFSStateException e)
            {
                // if the storage is in a bad state,
                Log.Warn("The storage directory is in an inconsistent state", e);
            }
            finally
            {
                storage.UnlockAll();
            }
            // if there is InconsistentFSStateException or the storage is not formatted,
            // format the storage. Although this format is done through the new
            // software, since in HA setup the SBN is rolled back through
            // "-bootstrapStandby", we should still be fine.
            if (!isFormatted && !Format(storage, nsInfo))
            {
                return(false);
            }
            // make sure there is no previous directory
            FSImage.CheckUpgrade(storage);
            // Do preUpgrade for each directory
            for (IEnumerator <Storage.StorageDirectory> it = storage.DirIterator(false); it.HasNext
                     ();)
            {
                Storage.StorageDirectory sd = it.Next();
                try
                {
                    NNUpgradeUtil.RenameCurToTmp(sd);
                }
                catch (IOException e)
                {
                    Log.Error("Failed to move aside pre-upgrade storage " + "in image directory " + sd
                              .GetRoot(), e);
                    throw;
                }
            }
            storage.SetStorageInfo(nsInfo);
            storage.SetBlockPoolID(nsInfo.GetBlockPoolID());
            return(true);
        }