Example #1
0
 /// <summary>Constructor</summary>
 /// <param name="length">the number of bytes the file has</param>
 /// <param name="isdir">if the path is a directory</param>
 /// <param name="block_replication">the replication factor</param>
 /// <param name="blocksize">the block size</param>
 /// <param name="modification_time">modification time</param>
 /// <param name="access_time">access time</param>
 /// <param name="permission">permission</param>
 /// <param name="owner">the owner of the path</param>
 /// <param name="group">the group of the path</param>
 /// <param name="path">the local name in java UTF8 encoding the same as that in-memory
 ///     </param>
 /// <param name="fileId">the file id</param>
 /// <param name="feInfo">the file's encryption info</param>
 public HdfsFileStatus(long length, bool isdir, int block_replication, long blocksize
                       , long modification_time, long access_time, FsPermission permission, string owner
                       , string group, byte[] symlink, byte[] path, long fileId, int childrenNum, FileEncryptionInfo
                       feInfo, byte storagePolicy)
 {
     // local name of the inode that's encoded in java UTF8
     // symlink target encoded in java UTF8 or null
     // Used by dir, not including dot and dotdot. Always zero for a regular file.
     this.length            = length;
     this.isdir             = isdir;
     this.block_replication = (short)block_replication;
     this.blocksize         = blocksize;
     this.modification_time = modification_time;
     this.access_time       = access_time;
     this.permission        = (permission == null) ? ((isdir || symlink != null) ? FsPermission
                                                      .GetDefault() : FsPermission.GetFileDefault()) : permission;
     this.owner         = (owner == null) ? string.Empty : owner;
     this.group         = (group == null) ? string.Empty : group;
     this.symlink       = symlink;
     this.path          = path;
     this.fileId        = fileId;
     this.childrenNum   = childrenNum;
     this.feInfo        = feInfo;
     this.storagePolicy = storagePolicy;
 }
        /// <summary>Create FileStatus by file INode</summary>
        /// <exception cref="System.IO.IOException"/>
        internal static HdfsFileStatus CreateFileStatus(FSDirectory fsd, string fullPath,
                                                        byte[] path, INode node, byte storagePolicy, int snapshot, bool isRawPath, INodesInPath
                                                        iip)
        {
            long size = 0;
            // length is zero for directories
            short replication = 0;
            long  blocksize   = 0;
            bool  isEncrypted;
            FileEncryptionInfo feInfo = isRawPath ? null : fsd.GetFileEncryptionInfo(node, snapshot
                                                                                     , iip);

            if (node.IsFile())
            {
                INodeFile fileNode = node.AsFile();
                size        = fileNode.ComputeFileSize(snapshot);
                replication = fileNode.GetFileReplication(snapshot);
                blocksize   = fileNode.GetPreferredBlockSize();
                isEncrypted = (feInfo != null) || (isRawPath && fsd.IsInAnEZ(INodesInPath.FromINode
                                                                                 (node)));
            }
            else
            {
                isEncrypted = fsd.IsInAnEZ(INodesInPath.FromINode(node));
            }
            int childrenNum = node.IsDirectory() ? node.AsDirectory().GetChildrenNum(snapshot
                                                                                     ) : 0;
            INodeAttributes nodeAttrs = fsd.GetAttributes(fullPath, path, node, snapshot);

            return(new HdfsFileStatus(size, node.IsDirectory(), replication, blocksize, node.
                                      GetModificationTime(snapshot), node.GetAccessTime(snapshot), GetPermissionForFileStatus
                                          (nodeAttrs, isEncrypted), nodeAttrs.GetUserName(), nodeAttrs.GetGroupName(), node
                                      .IsSymlink() ? node.AsSymlink().GetSymlink() : null, path, node.GetId(), childrenNum
                                      , feInfo, storagePolicy));
        }
        /// <summary>Create FileStatus with location info by file INode</summary>
        /// <exception cref="System.IO.IOException"/>
        private static HdfsLocatedFileStatus CreateLocatedFileStatus(FSDirectory fsd, string
                                                                     fullPath, byte[] path, INode node, byte storagePolicy, int snapshot, bool isRawPath
                                                                     , INodesInPath iip)
        {
            System.Diagnostics.Debug.Assert(fsd.HasReadLock());
            long size = 0;
            // length is zero for directories
            short              replication = 0;
            long               blocksize   = 0;
            LocatedBlocks      loc         = null;
            bool               isEncrypted;
            FileEncryptionInfo feInfo = isRawPath ? null : fsd.GetFileEncryptionInfo(node, snapshot
                                                                                     , iip);

            if (node.IsFile())
            {
                INodeFile fileNode = node.AsFile();
                size        = fileNode.ComputeFileSize(snapshot);
                replication = fileNode.GetFileReplication(snapshot);
                blocksize   = fileNode.GetPreferredBlockSize();
                bool inSnapshot = snapshot != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                  .CurrentStateId;
                bool isUc     = !inSnapshot && fileNode.IsUnderConstruction();
                long fileSize = !inSnapshot && isUc?fileNode.ComputeFileSizeNotIncludingLastUcBlock
                                    () : size;

                loc = fsd.GetFSNamesystem().GetBlockManager().CreateLocatedBlocks(fileNode.GetBlocks
                                                                                      (snapshot), fileSize, isUc, 0L, size, false, inSnapshot, feInfo);
                if (loc == null)
                {
                    loc = new LocatedBlocks();
                }
                isEncrypted = (feInfo != null) || (isRawPath && fsd.IsInAnEZ(INodesInPath.FromINode
                                                                                 (node)));
            }
            else
            {
                isEncrypted = fsd.IsInAnEZ(INodesInPath.FromINode(node));
            }
            int childrenNum = node.IsDirectory() ? node.AsDirectory().GetChildrenNum(snapshot
                                                                                     ) : 0;
            INodeAttributes       nodeAttrs = fsd.GetAttributes(fullPath, path, node, snapshot);
            HdfsLocatedFileStatus status    = new HdfsLocatedFileStatus(size, node.IsDirectory()
                                                                        , replication, blocksize, node.GetModificationTime(snapshot), node.GetAccessTime
                                                                            (snapshot), GetPermissionForFileStatus(nodeAttrs, isEncrypted), nodeAttrs.GetUserName
                                                                            (), nodeAttrs.GetGroupName(), node.IsSymlink() ? node.AsSymlink().GetSymlink() :
                                                                        null, path, node.GetId(), loc, childrenNum, feInfo, storagePolicy);

            // Set caching information for the located blocks.
            if (loc != null)
            {
                CacheManager cacheManager = fsd.GetFSNamesystem().GetCacheManager();
                foreach (LocatedBlock lb in loc.GetLocatedBlocks())
                {
                    cacheManager.SetCachedLocations(lb);
                }
            }
            return(status);
        }
Example #4
0
 public LocatedBlocks(long flength, bool isUnderConstuction, IList <LocatedBlock> blks
                      , LocatedBlock lastBlock, bool isLastBlockCompleted, FileEncryptionInfo feInfo)
 {
     fileLength               = flength;
     blocks                   = blks;
     underConstruction        = isUnderConstuction;
     this.lastLocatedBlock    = lastBlock;
     this.isLastBlockComplete = isLastBlockCompleted;
     this.fileEncryptionInfo  = feInfo;
 }
Example #5
0
 public LocatedBlocks()
 {
     // array of blocks with prioritized locations
     fileLength          = 0;
     blocks              = null;
     underConstruction   = false;
     lastLocatedBlock    = null;
     isLastBlockComplete = false;
     fileEncryptionInfo  = null;
 }
Example #6
0
 /// <summary>Constructor</summary>
 /// <param name="length">size</param>
 /// <param name="isdir">if this is directory</param>
 /// <param name="block_replication">the file's replication factor</param>
 /// <param name="blocksize">the file's block size</param>
 /// <param name="modification_time">most recent modification time</param>
 /// <param name="access_time">most recent access time</param>
 /// <param name="permission">permission</param>
 /// <param name="owner">owner</param>
 /// <param name="group">group</param>
 /// <param name="symlink">symbolic link</param>
 /// <param name="path">local path name in java UTF8 format</param>
 /// <param name="fileId">the file id</param>
 /// <param name="locations">block locations</param>
 /// <param name="feInfo">file encryption info</param>
 public HdfsLocatedFileStatus(long length, bool isdir, int block_replication, long
                              blocksize, long modification_time, long access_time, FsPermission permission, string
                              owner, string group, byte[] symlink, byte[] path, long fileId, LocatedBlocks locations
                              , int childrenNum, FileEncryptionInfo feInfo, byte storagePolicy)
     : base(length, isdir, block_replication, blocksize, modification_time, access_time
            , permission, owner, group, symlink, path, fileId, childrenNum, feInfo, storagePolicy
            )
 {
     this.locations = locations;
 }