Esempio n. 1
0
 /// <summary>Add a dir-diff pair</summary>
 internal virtual void AddDirDiff(INodeDirectory dir, byte[][] relativePath, DirectoryWithSnapshotFeature.ChildrenDiff
                                  diff)
 {
     dirDiffMap[dir] = diff;
     diffMap[dir]    = relativePath;
     // detect rename
     foreach (INode created in diff.GetList(Diff.ListType.Created))
     {
         if (created.IsReference())
         {
             SnapshotDiffInfo.RenameEntry entry = GetEntry(created.GetId());
             if (entry.GetTargetPath() == null)
             {
                 entry.SetTarget(created, relativePath);
             }
         }
     }
     foreach (INode deleted in diff.GetList(Diff.ListType.Deleted))
     {
         if (deleted is INodeReference.WithName)
         {
             SnapshotDiffInfo.RenameEntry entry = GetEntry(deleted.GetId());
             entry.SetSource(deleted, relativePath);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Interpret the ChildrenDiff and generate a list of
        /// <see cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotDiffReport.DiffReportEntry"/>
        /// .
        /// </summary>
        /// <param name="dirDiff">The ChildrenDiff.</param>
        /// <param name="parentPath">The relative path of the parent.</param>
        /// <param name="fromEarlier">
        /// True indicates
        /// <c>diff=later-earlier</c>
        /// ,
        /// False indicates
        /// <c>diff=earlier-later</c>
        /// </param>
        /// <param name="renameMap">A map containing information about rename operations.</param>
        /// <returns>
        /// A list of
        /// <see cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotDiffReport.DiffReportEntry"/>
        /// as the diff report.
        /// </returns>
        private IList <SnapshotDiffReport.DiffReportEntry> GenerateReport(DirectoryWithSnapshotFeature.ChildrenDiff
                                                                          dirDiff, byte[][] parentPath, bool fromEarlier, IDictionary <long, SnapshotDiffInfo.RenameEntry
                                                                                                                                       > renameMap)
        {
            IList <SnapshotDiffReport.DiffReportEntry> list = new AList <SnapshotDiffReport.DiffReportEntry
                                                                         >();
            IList <INode> created = dirDiff.GetList(Diff.ListType.Created);
            IList <INode> deleted = dirDiff.GetList(Diff.ListType.Deleted);

            byte[][] fullPath = new byte[parentPath.Length + 1][];
            System.Array.Copy(parentPath, 0, fullPath, 0, parentPath.Length);
            foreach (INode cnode in created)
            {
                SnapshotDiffInfo.RenameEntry entry = renameMap[cnode.GetId()];
                if (entry == null || !entry.IsRename())
                {
                    fullPath[fullPath.Length - 1] = cnode.GetLocalNameBytes();
                    list.AddItem(new SnapshotDiffReport.DiffReportEntry(fromEarlier ? SnapshotDiffReport.DiffType
                                                                        .Create : SnapshotDiffReport.DiffType.Delete, fullPath));
                }
            }
            foreach (INode dnode in deleted)
            {
                SnapshotDiffInfo.RenameEntry entry = renameMap[dnode.GetId()];
                if (entry != null && entry.IsRename())
                {
                    list.AddItem(new SnapshotDiffReport.DiffReportEntry(SnapshotDiffReport.DiffType.Rename
                                                                        , fromEarlier ? entry.GetSourcePath() : entry.GetTargetPath(), fromEarlier ? entry
                                                                        .GetTargetPath() : entry.GetSourcePath()));
                }
                else
                {
                    fullPath[fullPath.Length - 1] = dnode.GetLocalNameBytes();
                    list.AddItem(new SnapshotDiffReport.DiffReportEntry(fromEarlier ? SnapshotDiffReport.DiffType
                                                                        .Delete : SnapshotDiffReport.DiffType.Create, fullPath));
                }
            }
            return(list);
        }
Esempio n. 3
0
            /// <summary>
            /// Find the corresponding snapshot whose deleted list contains the given
            /// inode.
            /// </summary>
            /// <returns>
            /// the id of the snapshot.
            /// <see cref="Snapshot.NoSnapshotId"/>
            /// if the
            /// given inode is not in any of the snapshot.
            /// </returns>
            public virtual int FindSnapshotDeleted(INode child)
            {
                IList <DirectoryWithSnapshotFeature.DirectoryDiff> diffList = AsList();

                for (int i = diffList.Count - 1; i >= 0; i--)
                {
                    DirectoryWithSnapshotFeature.ChildrenDiff diff = diffList[i].diff;
                    int d = diff.SearchIndex(Diff.ListType.Deleted, child.GetLocalNameBytes());
                    if (d >= 0 && diff.GetList(Diff.ListType.Deleted)[d] == child)
                    {
                        return(diffList[i].GetSnapshotId());
                    }
                }
                return(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId);
            }