Exemplo n.º 1
0
        /// <summary>Finalize the upgrade.</summary>
        /// <remarks>
        /// Finalize the upgrade. The previous dir, if any, will be renamed and
        /// removed. After this is completed, rollback is no longer allowed.
        /// </remarks>
        /// <param name="sd">the storage directory to finalize</param>
        /// <exception cref="System.IO.IOException">in the event of error</exception>
        internal static void DoFinalize(Storage.StorageDirectory sd)
        {
            FilePath prevDir = sd.GetPreviousDir();

            if (!prevDir.Exists())
            {
                // already discarded
                Log.Info("Directory " + prevDir + " does not exist.");
                Log.Info("Finalize upgrade for " + sd.GetRoot() + " is not required.");
                return;
            }
            Log.Info("Finalizing upgrade of storage directory " + sd.GetRoot());
            Preconditions.CheckState(sd.GetCurrentDir().Exists(), "Current directory must exist."
                                     );
            FilePath tmpDir = sd.GetFinalizedTmp();

            // rename previous to tmp and remove
            NNStorage.Rename(prevDir, tmpDir);
            NNStorage.DeleteDir(tmpDir);
            Log.Info("Finalize upgrade for " + sd.GetRoot() + " is complete.");
        }
Exemplo n.º 2
0
        /// <summary>Perform rollback of the storage dir to the previous state.</summary>
        /// <remarks>
        /// Perform rollback of the storage dir to the previous state. The existing
        /// current dir is removed, and the previous dir is renamed to current.
        /// </remarks>
        /// <param name="sd">the storage directory to roll back.</param>
        /// <exception cref="System.IO.IOException">in the event of error</exception>
        internal static void DoRollBack(Storage.StorageDirectory sd)
        {
            FilePath prevDir = sd.GetPreviousDir();

            if (!prevDir.Exists())
            {
                return;
            }
            FilePath tmpDir = sd.GetRemovedTmp();

            Preconditions.CheckState(!tmpDir.Exists(), "removed.tmp directory must not exist for rollback."
                                     + "Consider restarting for recovery.");
            // rename current to tmp
            FilePath curDir = sd.GetCurrentDir();

            Preconditions.CheckState(curDir.Exists(), "Current directory must exist for rollback."
                                     );
            NNStorage.Rename(curDir, tmpDir);
            // rename previous to current
            NNStorage.Rename(prevDir, curDir);
            // delete tmp dir
            NNStorage.DeleteDir(tmpDir);
            Log.Info("Rollback of " + sd.GetRoot() + " is complete.");
        }