コード例 #1
0
        /// <exception cref="System.IO.IOException"/>
        internal static void DownloadEditsToStorage(Uri fsName, RemoteEditLog log, NNStorage
                                                    dstStorage)
        {
            System.Diagnostics.Debug.Assert(log.GetStartTxId() > 0 && log.GetEndTxId() > 0, "bad log: "
                                            + log);
            string fileid        = ImageServlet.GetParamStringForLog(log, dstStorage);
            string finalFileName = NNStorage.GetFinalizedEditsFileName(log.GetStartTxId(), log
                                                                       .GetEndTxId());
            IList <FilePath> finalFiles = dstStorage.GetFiles(NNStorage.NameNodeDirType.Edits,
                                                              finalFileName);

            System.Diagnostics.Debug.Assert(!finalFiles.IsEmpty(), "No checkpoint targets.");
            foreach (FilePath f in finalFiles)
            {
                if (f.Exists() && FileUtil.CanRead(f))
                {
                    Log.Info("Skipping download of remote edit log " + log + " since it already is stored locally at "
                             + f);
                    return;
                }
                else
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Dest file: " + f);
                    }
                }
            }
            long   milliTime   = Time.MonotonicNow();
            string tmpFileName = NNStorage.GetTemporaryEditsFileName(log.GetStartTxId(), log.
                                                                     GetEndTxId(), milliTime);
            IList <FilePath> tmpFiles = dstStorage.GetFiles(NNStorage.NameNodeDirType.Edits, tmpFileName
                                                            );

            GetFileClient(fsName, fileid, tmpFiles, dstStorage, false);
            Log.Info("Downloaded file " + tmpFiles[0].GetName() + " size " + finalFiles[0].Length
                         () + " bytes.");
            CheckpointFaultInjector.GetInstance().BeforeEditsRename();
            foreach (Storage.StorageDirectory sd in dstStorage.DirIterable(NNStorage.NameNodeDirType
                                                                           .Edits))
            {
                FilePath tmpFile = NNStorage.GetTemporaryEditsFile(sd, log.GetStartTxId(), log.GetEndTxId
                                                                       (), milliTime);
                FilePath finalizedFile = NNStorage.GetFinalizedEditsFile(sd, log.GetStartTxId(),
                                                                         log.GetEndTxId());
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Renaming " + tmpFile + " to " + finalizedFile);
                }
                bool success = tmpFile.RenameTo(finalizedFile);
                if (!success)
                {
                    Log.Warn("Unable to rename edits file from " + tmpFile + " to " + finalizedFile);
                }
            }
        }
コード例 #2
0
        private void CheckNNStorage(NNStorage storage, long imageTxId, long trashEndTxId)
        {
            IList <FilePath> finalizedEdits = storage.GetFiles(NNStorage.NameNodeDirType.Edits
                                                               , NNStorage.GetFinalizedEditsFileName(1, imageTxId));

            NUnit.Framework.Assert.IsTrue(FileExists(finalizedEdits));
            IList <FilePath> inprogressEdits = storage.GetFiles(NNStorage.NameNodeDirType.Edits
                                                                , NNStorage.GetInProgressEditsFileName(imageTxId + 1));

            // For rollback case we will have an inprogress file for future transactions
            NUnit.Framework.Assert.IsTrue(FileExists(inprogressEdits));
            if (trashEndTxId > 0)
            {
                IList <FilePath> trashedEdits = storage.GetFiles(NNStorage.NameNodeDirType.Edits,
                                                                 NNStorage.GetFinalizedEditsFileName(imageTxId + 1, trashEndTxId) + ".trash");
                NUnit.Framework.Assert.IsTrue(FileExists(trashedEdits));
            }
            string imageFileName = trashEndTxId > 0 ? NNStorage.GetImageFileName(imageTxId) :
                                   NNStorage.GetRollbackImageFileName(imageTxId);
            IList <FilePath> imageFiles = storage.GetFiles(NNStorage.NameNodeDirType.Image, imageFileName
                                                           );

            NUnit.Framework.Assert.IsTrue(FileExists(imageFiles));
        }