示例#1
0
 public virtual void PutDir(FsImageProto.INodeSection.INode p)
 {
     Preconditions.CheckState(!dirMap.Contains(p.GetId()));
     PBImageTextWriter.InMemoryMetadataDB.Dir dir = new PBImageTextWriter.InMemoryMetadataDB.Dir
                                                        (p.GetId(), p.GetName().ToStringUtf8());
     dirMap[p.GetId()] = dir;
 }
示例#2
0
 /// <exception cref="System.IO.IOException"/>
 private void DumpINodeSection(InputStream @in)
 {
     FsImageProto.INodeSection s = FsImageProto.INodeSection.ParseDelimitedFrom(@in);
     @out.Write("<INodeSection>");
     O("lastInodeId", s.GetLastInodeId());
     for (int i = 0; i < s.GetNumInodes(); ++i)
     {
         FsImageProto.INodeSection.INode p = FsImageProto.INodeSection.INode.ParseDelimitedFrom
                                                 (@in);
         @out.Write("<inode>");
         O("id", p.GetId()).O("type", p.GetType()).O("name", p.GetName().ToStringUtf8());
         if (p.HasFile())
         {
             DumpINodeFile(p.GetFile());
         }
         else
         {
             if (p.HasDirectory())
             {
                 DumpINodeDirectory(p.GetDirectory());
             }
             else
             {
                 if (p.HasSymlink())
                 {
                     DumpINodeSymlink(p.GetSymlink());
                 }
             }
         }
         @out.Write("</inode>\n");
     }
     @out.Write("</INodeSection>\n");
 }
示例#3
0
            private INodeSymlink LoadINodeSymlink(FsImageProto.INodeSection.INode n)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .Symlink);
                FsImageProto.INodeSection.INodeSymlink s = n.GetSymlink();
                PermissionStatus permissions             = LoadPermission(s.GetPermission(), parent.GetLoaderContext
                                                                              ().GetStringTable());
                INodeSymlink sym = new INodeSymlink(n.GetId(), n.GetName().ToByteArray(), permissions
                                                    , s.GetModificationTime(), s.GetAccessTime(), s.GetTarget().ToStringUtf8());

                return(sym);
            }
示例#4
0
            private INodeFile LoadINodeFile(FsImageProto.INodeSection.INode n)
            {
                System.Diagnostics.Debug.Assert(n.GetType() == FsImageProto.INodeSection.INode.Type
                                                .File);
                FsImageProto.INodeSection.INodeFile f  = n.GetFile();
                IList <HdfsProtos.BlockProto>       bp = f.GetBlocksList();
                short replication = (short)f.GetReplication();

                FSImageFormatProtobuf.LoaderContext state = parent.GetLoaderContext();
                BlockInfoContiguous[] blocks = new BlockInfoContiguous[bp.Count];
                for (int i = 0; i < e; ++i)
                {
                    blocks[i] = new BlockInfoContiguous(PBHelper.Convert(bp[i]), replication);
                }
                PermissionStatus permissions = LoadPermission(f.GetPermission(), parent.GetLoaderContext
                                                                  ().GetStringTable());
                INodeFile file = new INodeFile(n.GetId(), n.GetName().ToByteArray(), permissions,
                                               f.GetModificationTime(), f.GetAccessTime(), blocks, replication, f.GetPreferredBlockSize
                                                   (), unchecked ((byte)f.GetStoragePolicyID()));

                if (f.HasAcl())
                {
                    int[] entries = AclEntryStatusFormat.ToInt(LoadAclEntries(f.GetAcl(), state.GetStringTable
                                                                                  ()));
                    file.AddAclFeature(new AclFeature(entries));
                }
                if (f.HasXAttrs())
                {
                    file.AddXAttrFeature(new XAttrFeature(LoadXAttrs(f.GetXAttrs(), state.GetStringTable
                                                                         ())));
                }
                // under-construction information
                if (f.HasFileUC())
                {
                    FsImageProto.INodeSection.FileUnderConstructionFeature uc = f.GetFileUC();
                    file.ToUnderConstruction(uc.GetClientName(), uc.GetClientMachine());
                    if (blocks.Length > 0)
                    {
                        BlockInfoContiguous lastBlk = file.GetLastBlock();
                        // replace the last block of file
                        file.SetBlock(file.NumBlocks() - 1, new BlockInfoContiguousUnderConstruction(lastBlk
                                                                                                     , replication));
                    }
                }
                return(file);
            }
示例#5
0
        /// <summary>Return the INodeId of the specified path.</summary>
        /// <exception cref="System.IO.IOException"/>
        private long Lookup(string path)
        {
            Preconditions.CheckArgument(path.StartsWith("/"));
            long id = INodeId.RootInodeId;

            for (int offset = 0; offset < path.Length; offset = next)
            {
                next = path.IndexOf('/', offset + 1);
                if (next == -1)
                {
                    next = path.Length;
                }
                if (offset + 1 > next)
                {
                    break;
                }
                string component = Sharpen.Runtime.Substring(path, offset + 1, next);
                if (component.IsEmpty())
                {
                    continue;
                }
                long[] children = dirmap[id];
                if (children == null)
                {
                    throw new FileNotFoundException(path);
                }
                bool found = false;
                foreach (long cid in children)
                {
                    FsImageProto.INodeSection.INode child = FromINodeId(cid);
                    if (component.Equals(child.GetName().ToStringUtf8()))
                    {
                        found = true;
                        id    = child.GetId();
                        break;
                    }
                }
                if (!found)
                {
                    throw new FileNotFoundException(path);
                }
            }
            return(id);
        }
示例#6
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);
            }
示例#7
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void PutDir(FsImageProto.INodeSection.INode dir)
 {
     Preconditions.CheckArgument(dir.HasDirectory(), "INode %s (%s) is not a directory."
                                 , dir.GetId(), dir.GetName());
     dirMap.Put(ToBytes(dir.GetId()), ToBytes(dir.GetName().ToStringUtf8()));
 }
示例#8
0
        private IDictionary <string, object> GetFileStatus(FsImageProto.INodeSection.INode
                                                           inode, bool printSuffix)
        {
            IDictionary <string, object> map = Maps.NewHashMap();

            switch (inode.GetType())
            {
            case FsImageProto.INodeSection.INode.Type.File:
            {
                FsImageProto.INodeSection.INodeFile f = inode.GetFile();
                PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(f.GetPermission()
                                                                                , stringTable);
                map["accessTime"]       = f.GetAccessTime();
                map["blockSize"]        = f.GetPreferredBlockSize();
                map["group"]            = p.GetGroupName();
                map["length"]           = GetFileSize(f);
                map["modificationTime"] = f.GetModificationTime();
                map["owner"]            = p.GetUserName();
                map["pathSuffix"]       = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty;
                map["permission"]       = ToString(p.GetPermission());
                map["replication"]      = f.GetReplication();
                map["type"]             = inode.GetType();
                map["fileId"]           = inode.GetId();
                map["childrenNum"]      = 0;
                return(map);
            }

            case FsImageProto.INodeSection.INode.Type.Directory:
            {
                FsImageProto.INodeSection.INodeDirectory d = inode.GetDirectory();
                PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission()
                                                                                , stringTable);
                map["accessTime"]       = 0;
                map["blockSize"]        = 0;
                map["group"]            = p.GetGroupName();
                map["length"]           = 0;
                map["modificationTime"] = d.GetModificationTime();
                map["owner"]            = p.GetUserName();
                map["pathSuffix"]       = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty;
                map["permission"]       = ToString(p.GetPermission());
                map["replication"]      = 0;
                map["type"]             = inode.GetType();
                map["fileId"]           = inode.GetId();
                map["childrenNum"]      = dirmap.Contains(inode.GetId()) ? dirmap[inode.GetId()].Length
                                                 : 0;
                return(map);
            }

            case FsImageProto.INodeSection.INode.Type.Symlink:
            {
                FsImageProto.INodeSection.INodeSymlink d = inode.GetSymlink();
                PermissionStatus p = FSImageFormatPBINode.Loader.LoadPermission(d.GetPermission()
                                                                                , stringTable);
                map["accessTime"]       = d.GetAccessTime();
                map["blockSize"]        = 0;
                map["group"]            = p.GetGroupName();
                map["length"]           = 0;
                map["modificationTime"] = d.GetModificationTime();
                map["owner"]            = p.GetUserName();
                map["pathSuffix"]       = printSuffix ? inode.GetName().ToStringUtf8() : string.Empty;
                map["permission"]       = ToString(p.GetPermission());
                map["replication"]      = 0;
                map["type"]             = inode.GetType();
                map["symlink"]          = d.GetTarget().ToStringUtf8();
                map["fileId"]           = inode.GetId();
                map["childrenNum"]      = 0;
                return(map);
            }

            default:
            {
                return(null);
            }
            }
        }
示例#9
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());
        }