예제 #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);
         }
     }
 }
예제 #2
0
 private SnapshotDiffInfo.RenameEntry GetEntry(long inodeId)
 {
     SnapshotDiffInfo.RenameEntry entry = renameMap[inodeId];
     if (entry == null)
     {
         entry = new SnapshotDiffInfo.RenameEntry();
         renameMap[inodeId] = entry;
     }
     return(entry);
 }
예제 #3
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);
        }