/// <summary>Check whether the path is a valid DataNode data directory.</summary> private static void CheckDir(FilePath dataDir) { Storage.StorageDirectory sd = new Storage.StorageDirectory(dataDir); NUnit.Framework.Assert.IsTrue(sd.GetRoot().IsDirectory()); NUnit.Framework.Assert.IsTrue(sd.GetCurrentDir().IsDirectory()); NUnit.Framework.Assert.IsTrue(sd.GetVersionFile().IsFile()); }
/// <summary>Check whether the root is a valid BlockPoolSlice storage.</summary> private static void CheckDir(FilePath root, string bpid) { Storage.StorageDirectory sd = new Storage.StorageDirectory(root); FilePath bpRoot = new FilePath(sd.GetCurrentDir(), bpid); Storage.StorageDirectory bpSd = new Storage.StorageDirectory(bpRoot); NUnit.Framework.Assert.IsTrue(bpSd.GetRoot().IsDirectory()); NUnit.Framework.Assert.IsTrue(bpSd.GetCurrentDir().IsDirectory()); NUnit.Framework.Assert.IsTrue(bpSd.GetVersionFile().IsFile()); }
/// <exception cref="System.IO.IOException"/> private string GetClusterId(Configuration config) { // see if cluster id not empty. ICollection <URI> dirsToFormat = FSNamesystem.GetNamespaceDirs(config); IList <URI> editsToFormat = FSNamesystem.GetNamespaceEditsDirs(config); FSImage fsImage = new FSImage(config, dirsToFormat, editsToFormat); IEnumerator <Storage.StorageDirectory> sdit = fsImage.GetStorage().DirIterator(NNStorage.NameNodeDirType .Image); Storage.StorageDirectory sd = sdit.Next(); Properties props = Storage.ReadPropertiesFile(sd.GetVersionFile()); string cid = props.GetProperty("clusterID"); Log.Info("successfully formated : sd=" + sd.GetCurrentDir() + ";cid=" + cid); return(cid); }
/* 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(); }
/// <summary>Read properties from the VERSION file in the given storage directory.</summary> /// <exception cref="System.IO.IOException"/> public virtual void ReadProperties(Storage.StorageDirectory sd) { Properties props = ReadPropertiesFile(sd.GetVersionFile()); SetFieldsFromProperties(props, sd); }
/// <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(); }