Esempio n. 1
0
 /// <summary>verify that edits log and fsimage are in different directories and of a correct size
 ///     </summary>
 private void VerifyDifferentDirs(FSImage img, long expectedImgSize, long expectedEditsSize
                                  )
 {
     Storage.StorageDirectory sd = null;
     for (IEnumerator <Storage.StorageDirectory> it = img.GetStorage().DirIterator(); it
          .HasNext();)
     {
         sd = it.Next();
         if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Image))
         {
             img.GetStorage();
             FilePath imf = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Image, 0);
             Log.Info("--image file " + imf.GetAbsolutePath() + "; len = " + imf.Length() + "; expected = "
                      + expectedImgSize);
             NUnit.Framework.Assert.AreEqual(expectedImgSize, imf.Length());
         }
         else
         {
             if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Edits))
             {
                 img.GetStorage();
                 FilePath edf = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Edits, 0);
                 Log.Info("-- edits file " + edf.GetAbsolutePath() + "; len = " + edf.Length() + "; expected = "
                          + expectedEditsSize);
                 NUnit.Framework.Assert.AreEqual(expectedEditsSize, edf.Length());
             }
             else
             {
                 NUnit.Framework.Assert.Fail("Image/Edits directories are not different");
             }
         }
     }
 }
Esempio n. 2
0
        /* Flag if there is at least one storage dir that doesn't contain the newest
         * fstime */
        /* Flag set false if there are any "previous" directories found */
        // Track the name and edits dir with the latest times
        /// <exception cref="System.IO.IOException"/>
        internal override void InspectDirectory(Storage.StorageDirectory sd)
        {
            // Was the file just formatted?
            if (!sd.GetVersionFile().Exists())
            {
                hasOutOfDateStorageDirs = true;
                return;
            }
            bool imageExists = false;
            bool editsExists = false;

            // Determine if sd is image, edits or both
            if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Image))
            {
                imageExists = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Image).Exists();
                imageDirs.AddItem(sd.GetRoot().GetCanonicalPath());
            }
            if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Edits))
            {
                editsExists = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Edits).Exists();
                editsDirs.AddItem(sd.GetRoot().GetCanonicalPath());
            }
            long checkpointTime = ReadCheckpointTime(sd);

            checkpointTimes.AddItem(checkpointTime);
            if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Image) && (latestNameCheckpointTime
                                                                                     < checkpointTime) && imageExists)
            {
                latestNameCheckpointTime = checkpointTime;
                latestNameSD             = sd;
            }
            if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Edits) && (latestEditsCheckpointTime
                                                                                     < checkpointTime) && editsExists)
            {
                latestEditsCheckpointTime = checkpointTime;
                latestEditsSD             = sd;
            }
            // check that we have a valid, non-default checkpointTime
            if (checkpointTime <= 0L)
            {
                hasOutOfDateStorageDirs = true;
            }
            // set finalized flag
            isUpgradeFinalized = isUpgradeFinalized && !sd.GetPreviousDir().Exists();
        }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"/>
        internal override IList <FSImageStorageInspector.FSImageFile> GetLatestImages()
        {
            // We should have at least one image and one edits dirs
            if (latestNameSD == null)
            {
                throw new IOException("Image file is not found in " + imageDirs);
            }
            if (latestEditsSD == null)
            {
                throw new IOException("Edits file is not found in " + editsDirs);
            }
            // Make sure we are loading image and edits from same checkpoint
            if (latestNameCheckpointTime > latestEditsCheckpointTime && latestNameSD != latestEditsSD &&
                latestNameSD.GetStorageDirType() == NNStorage.NameNodeDirType.Image && latestEditsSD
                .GetStorageDirType() == NNStorage.NameNodeDirType.Edits)
            {
                // This is a rare failure when NN has image-only and edits-only
                // storage directories, and fails right after saving images,
                // in some of the storage directories, but before purging edits.
                // See -NOTE- in saveNamespace().
                Log.Error("This is a rare failure scenario!!!");
                Log.Error("Image checkpoint time " + latestNameCheckpointTime + " > edits checkpoint time "
                          + latestEditsCheckpointTime);
                Log.Error("Name-node will treat the image as the latest state of " + "the namespace. Old edits will be discarded."
                          );
            }
            else
            {
                if (latestNameCheckpointTime != latestEditsCheckpointTime)
                {
                    throw new IOException("Inconsistent storage detected, " + "image and edits checkpoint times do not match. "
                                          + "image checkpoint time = " + latestNameCheckpointTime + "edits checkpoint time = "
                                          + latestEditsCheckpointTime);
                }
            }
            needToSaveAfterRecovery = DoRecovery();
            FSImageStorageInspector.FSImageFile file = new FSImageStorageInspector.FSImageFile
                                                           (latestNameSD, NNStorage.GetStorageFile(latestNameSD, NNStorage.NameNodeFile.Image
                                                                                                   ), HdfsConstants.InvalidTxid);
            List <FSImageStorageInspector.FSImageFile> ret = new List <FSImageStorageInspector.FSImageFile
                                                                       >();

            ret.AddItem(file);
            return(ret);
        }
Esempio n. 4
0
        public virtual void TestSNNStartup()
        {
            //setUpConfig();
            Log.Info("--starting SecondNN startup test");
            // different name dirs
            config.Set(DFSConfigKeys.DfsNamenodeNameDirKey, Org.Apache.Hadoop.Hdfs.Server.Common.Util.FileAsURI
                           (new FilePath(hdfsDir, "name")).ToString());
            config.Set(DFSConfigKeys.DfsNamenodeEditsDirKey, Org.Apache.Hadoop.Hdfs.Server.Common.Util.FileAsURI
                           (new FilePath(hdfsDir, "name")).ToString());
            // same checkpoint dirs
            config.Set(DFSConfigKeys.DfsNamenodeCheckpointEditsDirKey, Org.Apache.Hadoop.Hdfs.Server.Common.Util.FileAsURI
                           (new FilePath(hdfsDir, "chkpt_edits")).ToString());
            config.Set(DFSConfigKeys.DfsNamenodeCheckpointDirKey, Org.Apache.Hadoop.Hdfs.Server.Common.Util.FileAsURI
                           (new FilePath(hdfsDir, "chkpt")).ToString());
            Log.Info("--starting NN ");
            MiniDFSCluster    cluster = null;
            SecondaryNameNode sn      = null;
            NameNode          nn      = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(config).ManageDataDfsDirs(false).ManageNameDfsDirs
                              (false).Build();
                cluster.WaitActive();
                nn = cluster.GetNameNode();
                NUnit.Framework.Assert.IsNotNull(nn);
                // start secondary node
                Log.Info("--starting SecondNN");
                sn = new SecondaryNameNode(config);
                NUnit.Framework.Assert.IsNotNull(sn);
                Log.Info("--doing checkpoint");
                sn.DoCheckpoint();
                // this shouldn't fail
                Log.Info("--done checkpoint");
                // now verify that image and edits are created in the different directories
                FSImage image = nn.GetFSImage();
                Storage.StorageDirectory sd = image.GetStorage().GetStorageDir(0);
                //only one
                NUnit.Framework.Assert.AreEqual(sd.GetStorageDirType(), NNStorage.NameNodeDirType
                                                .ImageAndEdits);
                image.GetStorage();
                FilePath imf = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Image, 0);
                image.GetStorage();
                FilePath edf = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Edits, 0);
                Log.Info("--image file " + imf.GetAbsolutePath() + "; len = " + imf.Length());
                Log.Info("--edits file " + edf.GetAbsolutePath() + "; len = " + edf.Length());
                FSImage chkpImage = sn.GetFSImage();
                VerifyDifferentDirs(chkpImage, imf.Length(), edf.Length());
            }
            catch (IOException e)
            {
                NUnit.Framework.Assert.Fail(StringUtils.StringifyException(e));
                System.Console.Error.WriteLine("checkpoint failed");
                throw;
            }
            finally
            {
                if (sn != null)
                {
                    sn.Shutdown();
                }
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Esempio n. 5
0
        /// <exception cref="System.IO.IOException"/>
        internal override void InspectDirectory(Storage.StorageDirectory sd)
        {
            // Was the directory just formatted?
            if (!sd.GetVersionFile().Exists())
            {
                Log.Info("No version file in " + sd.GetRoot());
                needToSave |= true;
                return;
            }
            // Check for a seen_txid file, which marks a minimum transaction ID that
            // must be included in our load plan.
            try
            {
                maxSeenTxId = Math.Max(maxSeenTxId, NNStorage.ReadTransactionIdFile(sd));
            }
            catch (IOException ioe)
            {
                Log.Warn("Unable to determine the max transaction ID seen by " + sd, ioe);
                return;
            }
            FilePath currentDir = sd.GetCurrentDir();

            FilePath[] filesInStorage;
            try
            {
                filesInStorage = FileUtil.ListFiles(currentDir);
            }
            catch (IOException ioe)
            {
                Log.Warn("Unable to inspect storage directory " + currentDir, ioe);
                return;
            }
            foreach (FilePath f in filesInStorage)
            {
                Log.Debug("Checking file " + f);
                string name = f.GetName();
                // Check for fsimage_*
                Matcher imageMatch = this.MatchPattern(name);
                if (imageMatch != null)
                {
                    if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Image))
                    {
                        try
                        {
                            long txid = long.Parse(imageMatch.Group(1));
                            foundImages.AddItem(new FSImageStorageInspector.FSImageFile(sd, f, txid));
                        }
                        catch (FormatException)
                        {
                            Log.Error("Image file " + f + " has improperly formatted " + "transaction ID");
                        }
                    }
                    else
                    {
                        // skip
                        Log.Warn("Found image file at " + f + " but storage directory is " + "not configured to contain images."
                                 );
                    }
                }
            }
            // set finalized flag
            isUpgradeFinalized = isUpgradeFinalized && !sd.GetPreviousDir().Exists();
        }