public static SnapshottableDirectoryStatus.Bean ToBean(INodeDirectory d) { return(new SnapshottableDirectoryStatus.Bean(d.GetFullPathName(), d.GetDirectorySnapshottableFeature ().GetNumSnapshots(), d.GetDirectorySnapshottableFeature().GetSnapshotQuota(), d .GetModificationTime(), short.ValueOf(Sharpen.Extensions.ToOctalString(d.GetFsPermissionShort ())), d.GetUserName(), d.GetGroupName())); }
/// <summary> /// Generate a /// <see cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotDiffReport"/> /// based on detailed diff information. /// </summary> /// <returns> /// A /// <see cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotDiffReport"/> /// describing the difference /// </returns> public virtual SnapshotDiffReport GenerateReport() { IList <SnapshotDiffReport.DiffReportEntry> diffReportList = new AList <SnapshotDiffReport.DiffReportEntry >(); foreach (KeyValuePair <INode, byte[][]> drEntry in diffMap) { INode node = drEntry.Key; byte[][] path = drEntry.Value; diffReportList.AddItem(new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType .Modify, path, null)); if (node.IsDirectory()) { IList <SnapshotDiffReport.DiffReportEntry> subList = GenerateReport(dirDiffMap[node ], path, IsFromEarlier(), renameMap); Sharpen.Collections.AddAll(diffReportList, subList); } } return(new SnapshotDiffReport(snapshotRoot.GetFullPathName(), Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .GetSnapshotName(from), Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .GetSnapshotName(to), diffReportList)); }
/// <summary> /// Remove the snapshot with the given name from /// <see cref="snapshotsByNames"/> /// , /// and delete all the corresponding DirectoryDiff. /// </summary> /// <param name="snapshotRoot">The directory where we take snapshots</param> /// <param name="snapshotName">The name of the snapshot to be removed</param> /// <param name="collectedBlocks">Used to collect information to update blocksMap</param> /// <returns> /// The removed snapshot. Null if no snapshot with the given name /// exists. /// </returns> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException"/> public virtual Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot RemoveSnapshot (BlockStoragePolicySuite bsps, INodeDirectory snapshotRoot, string snapshotName, INode.BlocksMapUpdateInfo collectedBlocks, IList <INode> removedINodes) { int i = SearchSnapshot(DFSUtil.String2Bytes(snapshotName)); if (i < 0) { throw new SnapshotException("Cannot delete snapshot " + snapshotName + " from path " + snapshotRoot.GetFullPathName() + ": the snapshot does not exist."); } else { Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = snapshotsByNames [i]; int prior = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.FindLatestSnapshot (snapshotRoot, snapshot.GetId()); try { QuotaCounts counts = snapshotRoot.CleanSubtree(bsps, snapshot.GetId(), prior, collectedBlocks , removedINodes); INodeDirectory parent = snapshotRoot.GetParent(); if (parent != null) { // there will not be any WithName node corresponding to the deleted // snapshot, thus only update the quota usage in the current tree parent.AddSpaceConsumed(counts.Negation(), true); } } catch (QuotaExceededException e) { INode.Log.Error("BUG: removeSnapshot increases namespace usage.", e); } // remove from snapshotsByNames after successfully cleaning the subtree snapshotsByNames.Remove(i); return(snapshot); } }
/// <summary>Find the snapshot matching the given name.</summary> /// <param name="snapshotRoot">The directory where snapshots were taken.</param> /// <param name="snapshotName">The name of the snapshot.</param> /// <returns>The corresponding snapshot. Null if snapshotName is null or empty.</returns> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException"> /// If snapshotName is not null or empty, but there /// is no snapshot matching the name. /// </exception> private Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot GetSnapshotByName (INodeDirectory snapshotRoot, string snapshotName) { Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = null; if (snapshotName != null && !snapshotName.IsEmpty()) { int index = SearchSnapshot(DFSUtil.String2Bytes(snapshotName)); if (index < 0) { throw new SnapshotException("Cannot find the snapshot of directory " + snapshotRoot .GetFullPathName() + " with name " + snapshotName); } s = snapshotsByNames[index]; } return(s); }