/// <summary> /// Load the /// <see cref="Org.Apache.Hadoop.Hdfs.Tools.Snapshot.SnapshotDiff"/> /// list for the INodeDirectoryWithSnapshot /// directory. /// </summary> /// <param name="dir">The snapshottable directory for loading.</param> /// <param name="in"> /// The /// <see cref="System.IO.DataInput"/> /// instance to read. /// </param> /// <param name="loader">The loader</param> /// <exception cref="System.IO.IOException"/> public static void LoadDirectoryDiffList(INodeDirectory dir, DataInput @in, FSImageFormat.Loader loader) { int size = @in.ReadInt(); if (dir.IsWithSnapshot()) { DirectoryWithSnapshotFeature.DirectoryDiffList diffs = dir.GetDiffs(); for (int i = 0; i < size; i++) { diffs.AddFirst(LoadDirectoryDiff(dir, @in, loader)); } } }
/// <exception cref="System.IO.IOException"/> private static FileDiff LoadFileDiff(FileDiff posterior, DataInput @in, FSImageFormat.Loader loader) { // 1. Read the id of the Snapshot root to identify the Snapshot Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = loader.GetSnapshot (@in); // 2. Load file size long fileSize = @in.ReadLong(); // 3. Load snapshotINode INodeFileAttributes snapshotINode = @in.ReadBoolean() ? loader.LoadINodeFileAttributes (@in) : null; return(new FileDiff(snapshot.GetId(), snapshotINode, posterior, fileSize)); }
> Read(DataInput @in, FSImageFormat.Loader loader) { snapshotCounter = @in.ReadInt(); numSnapshots.Set(@in.ReadInt()); // read snapshots IDictionary <int, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot> snapshotMap = new Dictionary <int, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot> (); for (int i = 0; i < numSnapshots.Get(); i++) { Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .Read(@in, loader); snapshotMap[s.GetId()] = s; } return(snapshotMap); }
/// <summary>Load snapshots and snapshotQuota for a Snapshottable directory.</summary> /// <param name="snapshottableParent">The snapshottable directory for loading.</param> /// <param name="numSnapshots">The number of snapshots that the directory has.</param> /// <param name="loader">The loader</param> /// <exception cref="System.IO.IOException"/> public static void LoadSnapshotList(INodeDirectory snapshottableParent, int numSnapshots , DataInput @in, FSImageFormat.Loader loader) { DirectorySnapshottableFeature sf = snapshottableParent.GetDirectorySnapshottableFeature (); Preconditions.CheckArgument(sf != null); for (int i = 0; i < numSnapshots; i++) { // read snapshots Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = loader.GetSnapshot(@in ); s.GetRoot().SetParent(snapshottableParent); sf.AddSnapshot(s); } int snapshotQuota = @in.ReadInt(); snapshottableParent.SetSnapshotQuota(snapshotQuota); }
/// <summary>Load the deleted list from the fsimage.</summary> /// <param name="parent">The directory that the deleted list belongs to.</param> /// <param name="createdList"> /// The created list associated with the deleted list in /// the same Diff. /// </param> /// <param name="in"> /// The /// <see cref="System.IO.DataInput"/> /// to read. /// </param> /// <param name="loader"> /// The /// <see cref="Loader"/> /// instance. /// </param> /// <returns>The deleted list.</returns> /// <exception cref="System.IO.IOException"/> private static IList <INode> LoadDeletedList(INodeDirectory parent, IList <INode> createdList , DataInput @in, FSImageFormat.Loader loader) { int deletedSize = @in.ReadInt(); IList <INode> deletedList = new AList <INode>(deletedSize); for (int i = 0; i < deletedSize; i++) { INode deleted = loader.LoadINodeWithLocalName(true, @in, true); deletedList.AddItem(deleted); // set parent: the parent field of an INode in the deleted list is not // useful, but set the parent here to be consistent with the original // fsdir tree. deleted.SetParent(parent); if (deleted.IsFile()) { loader.UpdateBlocksMap(deleted.AsFile()); } } return(deletedList); }
/// <exception cref="System.IO.IOException"/> public static FileDiffList LoadFileDiffList(DataInput @in, FSImageFormat.Loader loader ) { int size = @in.ReadInt(); if (size == -1) { return(null); } else { FileDiffList diffs = new FileDiffList(); FileDiff posterior = null; for (int i = 0; i < size; i++) { FileDiff d = LoadFileDiff(posterior, @in, loader); diffs.AddFirst(d); posterior = d; } return(diffs); } }
/// <exception cref="System.IO.IOException"/> internal static Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot Read(DataInput @in, FSImageFormat.Loader loader) { int snapshotId = @in.ReadInt(); INode root = loader.LoadINodeWithLocalName(false, @in, false); return(new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(snapshotId, root .AsDirectory(), null)); }
/// <exception cref="System.IO.IOException"/> public virtual INodeReference.WithCount LoadINodeReferenceWithCount(bool isSnapshotINode , DataInput @in, FSImageFormat.Loader loader) { bool firstReferred = @in.ReadBoolean(); INodeReference.WithCount withCount; if (firstReferred) { INode referred = loader.LoadINodeWithLocalName(isSnapshotINode, @in, true); withCount = new INodeReference.WithCount(null, referred); referenceMap[withCount.GetId()] = withCount; } else { long id = @in.ReadLong(); withCount = referenceMap[id]; } return(withCount); }
/// <summary> /// Load /// <see cref="DirectoryDiff"/> /// from fsimage. /// </summary> /// <param name="parent">The directory that the SnapshotDiff belongs to.</param> /// <param name="in"> /// The /// <see cref="System.IO.DataInput"/> /// instance to read. /// </param> /// <param name="loader"> /// The /// <see cref="Loader"/> /// instance that this loading procedure is /// using. /// </param> /// <returns> /// A /// <see cref="DirectoryDiff"/> /// . /// </returns> /// <exception cref="System.IO.IOException"/> private static DirectoryWithSnapshotFeature.DirectoryDiff LoadDirectoryDiff(INodeDirectory parent, DataInput @in, FSImageFormat.Loader loader) { // 1. Read the full path of the Snapshot root to identify the Snapshot Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = loader.GetSnapshot (@in); // 2. Load DirectoryDiff#childrenSize int childrenSize = @in.ReadInt(); // 3. Load DirectoryDiff#snapshotINode INodeDirectoryAttributes snapshotINode = LoadSnapshotINodeInDirectoryDiff(snapshot , @in, loader); // 4. Load the created list in SnapshotDiff#Diff IList <INode> createdList = LoadCreatedList(parent, @in); // 5. Load the deleted list in SnapshotDiff#Diff IList <INode> deletedList = LoadDeletedList(parent, createdList, @in, loader); // 6. Compose the SnapshotDiff IList <DirectoryWithSnapshotFeature.DirectoryDiff> diffs = parent.GetDiffs().AsList (); DirectoryWithSnapshotFeature.DirectoryDiff sdiff = new DirectoryWithSnapshotFeature.DirectoryDiff (snapshot.GetId(), snapshotINode, diffs.IsEmpty() ? null : diffs[0], childrenSize , createdList, deletedList, snapshotINode == snapshot.GetRoot()); return(sdiff); }
/// <summary> /// Load the snapshotINode field of /// <see cref="AbstractINodeDiff{N, A, D}"/> /// . /// </summary> /// <param name="snapshot"> /// The Snapshot associated with the /// <see cref="AbstractINodeDiff{N, A, D}"/> /// . /// </param> /// <param name="in"> /// The /// <see cref="System.IO.DataInput"/> /// to read. /// </param> /// <param name="loader"> /// The /// <see cref="Loader"/> /// instance that this loading procedure is /// using. /// </param> /// <returns>The snapshotINode.</returns> /// <exception cref="System.IO.IOException"/> private static INodeDirectoryAttributes LoadSnapshotINodeInDirectoryDiff(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot, DataInput @in, FSImageFormat.Loader loader) { // read the boolean indicating whether snapshotINode == Snapshot.Root bool useRoot = @in.ReadBoolean(); if (useRoot) { return(snapshot.GetRoot()); } else { // another boolean is used to indicate whether snapshotINode is non-null return(@in.ReadBoolean() ? loader.LoadINodeDirectoryAttributes(@in) : null); } }