Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestCheckpoint()
        {
            Configuration conf = new Configuration();

            conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1);
            conf.SetInt(DFSConfigKeys.DfsNamenodeCheckpointPeriodKey, 1);
            MiniQJMHACluster cluster = null;
            Path             foo     = new Path("/foo");

            try
            {
                cluster = new MiniQJMHACluster.Builder(conf).Build();
                MiniDFSCluster dfsCluster = cluster.GetDfsCluster();
                dfsCluster.WaitActive();
                dfsCluster.TransitionToActive(0);
                DistributedFileSystem dfs = dfsCluster.GetFileSystem(0);
                // start rolling upgrade
                RollingUpgradeInfo info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare
                                                             );
                NUnit.Framework.Assert.IsTrue(info.IsStarted());
                QueryForPreparation(dfs);
                dfs.Mkdirs(foo);
                long txid = dfs.RollEdits();
                NUnit.Framework.Assert.IsTrue(txid > 0);
                int retries = 0;
                while (++retries < 5)
                {
                    NNStorage storage = dfsCluster.GetNamesystem(1).GetFSImage().GetStorage();
                    if (storage.GetFsImageName(txid - 1) != null)
                    {
                        return;
                    }
                    Sharpen.Thread.Sleep(1000);
                }
                NUnit.Framework.Assert.Fail("new checkpoint does not exist");
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Exemplo n.º 2
0
        public virtual bool DoCheckpoint()
        {
            checkpointImage.EnsureCurrentDirExists();
            NNStorage dstStorage = checkpointImage.GetStorage();
            // Tell the namenode to start logging transactions in a new edit file
            // Returns a token that would be used to upload the merged image.
            CheckpointSignature sig  = namenode.RollEditLog();
            bool loadImage           = false;
            bool isFreshCheckpointer = (checkpointImage.GetNamespaceID() == 0);
            bool isSameCluster       = (dstStorage.VersionSupportsFederation(NameNodeLayoutVersion.
                                                                             Features) && sig.IsSameCluster(checkpointImage)) || (!dstStorage.VersionSupportsFederation
                                                                                                                                      (NameNodeLayoutVersion.Features) && sig.NamespaceIdMatches(checkpointImage));

            if (isFreshCheckpointer || (isSameCluster && !sig.StorageVersionMatches(checkpointImage
                                                                                    .GetStorage())))
            {
                // if we're a fresh 2NN, or if we're on the same cluster and our storage
                // needs an upgrade, just take the storage info from the server.
                dstStorage.SetStorageInfo(sig);
                dstStorage.SetClusterID(sig.GetClusterID());
                dstStorage.SetBlockPoolID(sig.GetBlockpoolID());
                loadImage = true;
            }
            sig.ValidateStorageInfo(checkpointImage);
            // error simulation code for junit test
            CheckpointFaultInjector.GetInstance().AfterSecondaryCallsRollEditLog();
            RemoteEditLogManifest manifest = namenode.GetEditLogManifest(sig.mostRecentCheckpointTxId
                                                                         + 1);

            // Fetch fsimage and edits. Reload the image if previous merge failed.
            loadImage |= DownloadCheckpointFiles(fsName, checkpointImage, sig, manifest) | checkpointImage
                         .HasMergeError();
            try
            {
                DoMerge(sig, manifest, loadImage, checkpointImage, namesystem);
            }
            catch (IOException ioe)
            {
                // A merge error occurred. The in-memory file system state may be
                // inconsistent, so the image and edits need to be reloaded.
                checkpointImage.SetMergeError();
                throw;
            }
            // Clear any error since merge was successful.
            checkpointImage.ClearMergeError();
            //
            // Upload the new image into the NameNode. Then tell the Namenode
            // to make this new uploaded image as the most current image.
            //
            long txid = checkpointImage.GetLastAppliedTxId();

            TransferFsImage.UploadImageFromStorage(fsName, conf, dstStorage, NNStorage.NameNodeFile
                                                   .Image, txid);
            // error simulation code for junit test
            CheckpointFaultInjector.GetInstance().AfterSecondaryUploadsNewImage();
            Log.Warn("Checkpoint done. New Image Size: " + dstStorage.GetFsImageName(txid).Length
                         ());
            if (legacyOivImageDir != null && !legacyOivImageDir.IsEmpty())
            {
                try
                {
                    checkpointImage.SaveLegacyOIVImage(namesystem, legacyOivImageDir, new Canceler());
                }
                catch (IOException e)
                {
                    Log.Warn("Failed to write legacy OIV image: ", e);
                }
            }
            return(loadImage);
        }