internal Loader(Configuration conf, FSNamesystem fsn, bool requireSameLayoutVersion
                 )
 {
     this.conf = conf;
     this.fsn  = fsn;
     this.ctx  = new FSImageFormatProtobuf.LoaderContext();
     this.requireSameLayoutVersion = requireSameLayoutVersion;
 }
Esempio n. 2
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);
            }
Esempio n. 3
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);
            }