示例#1
0
 /// <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);
     }
 }
示例#2
0
        /// <exception cref="System.IO.IOException"/>
        private void DumpSnapshotDiffSection(InputStream @in)
        {
            @out.Write("<SnapshotDiffSection>");
            while (true)
            {
                FsImageProto.SnapshotDiffSection.DiffEntry e = FsImageProto.SnapshotDiffSection.DiffEntry
                                                               .ParseDelimitedFrom(@in);
                if (e == null)
                {
                    break;
                }
                @out.Write("<diff>");
                O("inodeid", e.GetInodeId());
                switch (e.GetType())
                {
                case FsImageProto.SnapshotDiffSection.DiffEntry.Type.Filediff:
                {
                    for (int i = 0; i < e.GetNumOfDiff(); ++i)
                    {
                        @out.Write("<filediff>");
                        FsImageProto.SnapshotDiffSection.FileDiff f = FsImageProto.SnapshotDiffSection.FileDiff
                                                                      .ParseDelimitedFrom(@in);
                        O("snapshotId", f.GetSnapshotId()).O("size", f.GetFileSize()).O("name", f.GetName
                                                                                            ().ToStringUtf8());
                        @out.Write("</filediff>\n");
                    }
                    break;
                }

                case FsImageProto.SnapshotDiffSection.DiffEntry.Type.Directorydiff:
                {
                    for (int i = 0; i < e.GetNumOfDiff(); ++i)
                    {
                        @out.Write("<dirdiff>");
                        FsImageProto.SnapshotDiffSection.DirectoryDiff d = FsImageProto.SnapshotDiffSection.DirectoryDiff
                                                                           .ParseDelimitedFrom(@in);
                        O("snapshotId", d.GetSnapshotId()).O("isSnapshotroot", d.GetIsSnapshotRoot()).O("childrenSize"
                                                                                                        , d.GetChildrenSize()).O("name", d.GetName().ToStringUtf8());
                        for (int j = 0; j < d.GetCreatedListSize(); ++j)
                        {
                            FsImageProto.SnapshotDiffSection.CreatedListEntry ce = FsImageProto.SnapshotDiffSection.CreatedListEntry
                                                                                   .ParseDelimitedFrom(@in);
                            @out.Write("<created>");
                            O("name", ce.GetName().ToStringUtf8());
                            @out.Write("</created>\n");
                        }
                        foreach (long did in d.GetDeletedINodeList())
                        {
                            @out.Write("<deleted>");
                            O("inode", did);
                            @out.Write("</deleted>\n");
                        }
                        foreach (int dRefid in d.GetDeletedINodeRefList())
                        {
                            @out.Write("<deleted>");
                            O("inodereference-index", dRefid);
                            @out.Write("</deleted>\n");
                        }
                        @out.Write("</dirdiff>\n");
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
                @out.Write("</diff>");
            }
            @out.Write("</SnapshotDiffSection>\n");
        }