Exemplo n.º 1
0
 private void DumpINodeDirectory(FsImageProto.INodeSection.INodeDirectory d)
 {
     O("mtime", d.GetModificationTime()).O("permission", DumpPermission(d.GetPermission
                                                                            ()));
     if (d.HasDsQuota() && d.HasNsQuota())
     {
         O("nsquota", d.GetNsQuota()).O("dsquota", d.GetDsQuota());
     }
 }
Exemplo n.º 2
0
            public static INodeDirectory LoadINodeDirectory(FsImageProto.INodeSection.INode n
                                                            , FSImageFormatProtobuf.LoaderContext state)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .Directory);
                FsImageProto.INodeSection.INodeDirectory d = n.GetDirectory();
                PermissionStatus permissions = LoadPermission(d.GetPermission(), state.GetStringTable
                                                                  ());
                INodeDirectory dir = new INodeDirectory(n.GetId(), n.GetName().ToByteArray(), permissions
                                                        , d.GetModificationTime());
                long nsQuota = d.GetNsQuota();
                long dsQuota = d.GetDsQuota();

                if (nsQuota >= 0 || dsQuota >= 0)
                {
                    dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().NameSpaceQuota
                                                         (nsQuota).StorageSpaceQuota(dsQuota).Build());
                }
                EnumCounters <StorageType> typeQuotas = null;

                if (d.HasTypeQuotas())
                {
                    ImmutableList <QuotaByStorageTypeEntry> qes = LoadQuotaByStorageTypeEntries(d.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());
                        }
                    }
                    if (typeQuotas.AnyGreaterOrEqual(0))
                    {
                        DirectoryWithQuotaFeature q = dir.GetDirectoryWithQuotaFeature();
                        if (q == null)
                        {
                            dir.AddDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder().TypeQuotas
                                                                 (typeQuotas).Build());
                        }
                        else
                        {
                            q.SetQuota(typeQuotas);
                        }
                    }
                }
                if (d.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(d.GetAcl(), state.GetStringTable
                                                                                  ()));
                    dir.AddAclFeature(new AclFeature(entries));
                }
                if (d.HasXAttrs())
                {
                    dir.AddXAttrFeature(new XAttrFeature(LoadXAttrs(d.GetXAttrs(), state.GetStringTable
                                                                        ())));
                }
                return(dir);
            }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
0
        protected internal override string GetEntry(string parent, FsImageProto.INodeSection.INode
                                                    inode)
        {
            StringBuilder buffer    = new StringBuilder();
            string        inodeName = inode.GetName().ToStringUtf8();
            Path          path      = new Path(parent.IsEmpty() ? "/" : parent, inodeName.IsEmpty() ? "/" :
                                               inodeName);

            buffer.Append(path.ToString());
            PermissionStatus p = null;

            switch (inode.GetType())
            {
            case FsImageProto.INodeSection.INode.Type.File:
            {
                FsImageProto.INodeSection.INodeFile file = inode.GetFile();
                p = GetPermission(file.GetPermission());
                Append(buffer, file.GetReplication());
                Append(buffer, FormatDate(file.GetModificationTime()));
                Append(buffer, FormatDate(file.GetAccessTime()));
                Append(buffer, file.GetPreferredBlockSize());
                Append(buffer, file.GetBlocksCount());
                Append(buffer, FSImageLoader.GetFileSize(file));
                Append(buffer, 0);
                // NS_QUOTA
                Append(buffer, 0);
                // DS_QUOTA
                break;
            }

            case FsImageProto.INodeSection.INode.Type.Directory:
            {
                FsImageProto.INodeSection.INodeDirectory dir = inode.GetDirectory();
                p = GetPermission(dir.GetPermission());
                Append(buffer, 0);
                // Replication
                Append(buffer, FormatDate(dir.GetModificationTime()));
                Append(buffer, FormatDate(0));
                // Access time.
                Append(buffer, 0);
                // Block size.
                Append(buffer, 0);
                // Num blocks.
                Append(buffer, 0);
                // Num bytes.
                Append(buffer, dir.GetNsQuota());
                Append(buffer, dir.GetDsQuota());
                break;
            }

            case FsImageProto.INodeSection.INode.Type.Symlink:
            {
                FsImageProto.INodeSection.INodeSymlink s = inode.GetSymlink();
                p = GetPermission(s.GetPermission());
                Append(buffer, 0);
                // Replication
                Append(buffer, FormatDate(s.GetModificationTime()));
                Append(buffer, FormatDate(s.GetAccessTime()));
                Append(buffer, 0);
                // Block size.
                Append(buffer, 0);
                // Num blocks.
                Append(buffer, 0);
                // Num bytes.
                Append(buffer, 0);
                // NS_QUOTA
                Append(buffer, 0);
                // DS_QUOTA
                break;
            }

            default:
            {
                break;
            }
            }
            System.Diagnostics.Debug.Assert(p != null);
            Append(buffer, p.GetPermission().ToString());
            Append(buffer, p.GetUserName());
            Append(buffer, p.GetGroupName());
            return(buffer.ToString());
        }