/// <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)); } } }
/// <summary>Load DirectoryDiff list for a directory with snapshot feature</summary> /// <exception cref="System.IO.IOException"/> private void LoadDirectoryDiffList(InputStream @in, INodeDirectory dir, int size, IList <INodeReference> refList) { if (!dir.IsWithSnapshot()) { dir.AddSnapshotFeature(null); } DirectoryWithSnapshotFeature.DirectoryDiffList diffs = dir.GetDiffs(); FSImageFormatProtobuf.LoaderContext state = parent.GetLoaderContext(); for (int i = 0; i < size; i++) { // load a directory diff FsImageProto.SnapshotDiffSection.DirectoryDiff diffInPb = FsImageProto.SnapshotDiffSection.DirectoryDiff .ParseDelimitedFrom(@in); int snapshotId = diffInPb.GetSnapshotId(); Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = snapshotMap[snapshotId ]; int childrenSize = diffInPb.GetChildrenSize(); bool useRoot = diffInPb.GetIsSnapshotRoot(); INodeDirectoryAttributes copy = null; if (useRoot) { copy = snapshot.GetRoot(); } else { if (diffInPb.HasSnapshotCopy()) { FsImageProto.INodeSection.INodeDirectory dirCopyInPb = diffInPb.GetSnapshotCopy(); byte[] name = diffInPb.GetName().ToByteArray(); PermissionStatus permission = FSImageFormatPBINode.Loader.LoadPermission(dirCopyInPb .GetPermission(), state.GetStringTable()); AclFeature acl = null; if (dirCopyInPb.HasAcl()) { int[] entries = AclEntryStatusFormat.ToInt(FSImageFormatPBINode.Loader.LoadAclEntries (dirCopyInPb.GetAcl(), state.GetStringTable())); acl = new AclFeature(entries); } XAttrFeature xAttrs = null; if (dirCopyInPb.HasXAttrs()) { xAttrs = new XAttrFeature(FSImageFormatPBINode.Loader.LoadXAttrs(dirCopyInPb.GetXAttrs (), state.GetStringTable())); } long modTime = dirCopyInPb.GetModificationTime(); bool noQuota = dirCopyInPb.GetNsQuota() == -1 && dirCopyInPb.GetDsQuota() == -1 && (!dirCopyInPb.HasTypeQuotas()); if (noQuota) { copy = new INodeDirectoryAttributes.SnapshotCopy(name, permission, acl, modTime, xAttrs); } else { EnumCounters <StorageType> typeQuotas = null; if (dirCopyInPb.HasTypeQuotas()) { ImmutableList <QuotaByStorageTypeEntry> qes = FSImageFormatPBINode.Loader.LoadQuotaByStorageTypeEntries (dirCopyInPb.GetTypeQuotas()); typeQuotas = new EnumCounters <StorageType>(typeof(StorageType), HdfsConstants.QuotaReset ); foreach (QuotaByStorageTypeEntry qe in qes) { if (qe.GetQuota() >= 0 && qe.GetStorageType() != null && qe.GetStorageType().SupportTypeQuota ()) { typeQuotas.Set(qe.GetStorageType(), qe.GetQuota()); } } } copy = new INodeDirectoryAttributes.CopyWithQuota(name, permission, acl, modTime, dirCopyInPb.GetNsQuota(), dirCopyInPb.GetDsQuota(), typeQuotas, xAttrs); } } } // load created list IList <INode> clist = LoadCreatedList(@in, dir, diffInPb.GetCreatedListSize()); // load deleted list IList <INode> dlist = LoadDeletedList(refList, @in, dir, diffInPb.GetDeletedINodeList (), diffInPb.GetDeletedINodeRefList()); // create the directory diff DirectoryWithSnapshotFeature.DirectoryDiff diff = new DirectoryWithSnapshotFeature.DirectoryDiff (snapshotId, copy, null, childrenSize, clist, dlist, useRoot); diffs.AddFirst(diff); } }
public DirectoryWithSnapshotFeature(DirectoryWithSnapshotFeature.DirectoryDiffList diffs) { this.diffs = diffs != null ? diffs : new DirectoryWithSnapshotFeature.DirectoryDiffList (); }
/// <summary>Destroy a subtree under a DstReference node.</summary> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/> public static void DestroyDstSubtree(BlockStoragePolicySuite bsps, INode inode, int snapshot, int prior, INode.BlocksMapUpdateInfo collectedBlocks, IList <INode> removedINodes ) { Preconditions.CheckArgument(prior != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .NoSnapshotId); if (inode.IsReference()) { if (inode is INodeReference.WithName && snapshot != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .CurrentStateId) { // this inode has been renamed before the deletion of the DstReference // subtree inode.CleanSubtree(bsps, snapshot, prior, collectedBlocks, removedINodes); } else { // for DstReference node, continue this process to its subtree DestroyDstSubtree(bsps, inode.AsReference().GetReferredINode(), snapshot, prior, collectedBlocks, removedINodes); } } else { if (inode.IsFile()) { inode.CleanSubtree(bsps, snapshot, prior, collectedBlocks, removedINodes); } else { if (inode.IsDirectory()) { IDictionary <INode, INode> excludedNodes = null; INodeDirectory dir = inode.AsDirectory(); DirectoryWithSnapshotFeature sf = dir.GetDirectoryWithSnapshotFeature(); if (sf != null) { DirectoryWithSnapshotFeature.DirectoryDiffList diffList = sf.GetDiffs(); DirectoryWithSnapshotFeature.DirectoryDiff priorDiff = diffList.GetDiffById(prior ); if (priorDiff != null && priorDiff.GetSnapshotId() == prior) { IList <INode> dList = priorDiff.diff.GetList(Diff.ListType.Deleted); excludedNodes = CloneDiffList(dList); } if (snapshot != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId) { diffList.DeleteSnapshotDiff(bsps, snapshot, prior, dir, collectedBlocks, removedINodes ); } priorDiff = diffList.GetDiffById(prior); if (priorDiff != null && priorDiff.GetSnapshotId() == prior) { priorDiff.diff.DestroyCreatedList(bsps, dir, collectedBlocks, removedINodes); } } foreach (INode child in inode.AsDirectory().GetChildrenList(prior)) { if (excludedNodes != null && excludedNodes.Contains(child)) { continue; } DestroyDstSubtree(bsps, child, snapshot, prior, collectedBlocks, removedINodes); } } } } }