示例#1
0
 /// <param name="offset">start endpoint (inclusive)</param>
 /// <param name="length">number of path components</param>
 /// <returns>sub-list of the path</returns>
 public virtual IList <string> GetPath(int offset, int length)
 {
     Preconditions.CheckArgument(offset >= 0 && length >= 0 && offset + length <= path
                                 .Length);
     ImmutableList.Builder <string> components = ImmutableList.Builder();
     for (int i = offset; i < offset + length; i++)
     {
         components.Add(DFSUtil.Bytes2String(path[i]));
     }
     return((ImmutableList <string>)components.Build());
 }
示例#2
0
            internal static string GetPathString(byte[] path)
            {
                string pathStr = DFSUtil.Bytes2String(path);

                if (pathStr.IsEmpty())
                {
                    return(Path.CurDir);
                }
                else
                {
                    return(Path.CurDir + Path.Separator + pathStr);
                }
            }
示例#3
0
        /// <summary>Given some components, create a path name.</summary>
        /// <param name="components">The path components</param>
        /// <param name="start">index</param>
        /// <param name="end">index</param>
        /// <returns>concatenated path</returns>
        private static string ConstructPath(byte[][] components, int start, int end)
        {
            StringBuilder buf = new StringBuilder();

            for (int i = start; i < end; i++)
            {
                buf.Append(DFSUtil.Bytes2String(components[i]));
                if (i < end - 1)
                {
                    buf.Append(Path.Separator);
                }
            }
            return(buf.ToString());
        }
        /// <returns>Full path of the file</returns>
        public virtual Path GetFullPath()
        {
            string parentFullPathStr = (parentFullPath == null || parentFullPath.Length == 0)
                                 ? null : DFSUtil.Bytes2String(parentFullPath);

            if (parentFullPathStr == null && dirStatus.GetLocalNameInBytes().Length == 0)
            {
                // root
                return(new Path("/"));
            }
            else
            {
                return(parentFullPathStr == null ? new Path(dirStatus.GetLocalName()) : new Path(
                           parentFullPathStr, dirStatus.GetLocalName()));
            }
        }
示例#5
0
        private INodeAttributes GetINodeAttrs(byte[][] pathByNameArr, int pathIdx, INode
                                              inode, int snapshotId)
        {
            INodeAttributes inodeAttrs = inode.GetSnapshotINode(snapshotId);

            if (GetAttributesProvider() != null)
            {
                string[] elements = new string[pathIdx + 1];
                for (int i = 0; i < elements.Length; i++)
                {
                    elements[i] = DFSUtil.Bytes2String(pathByNameArr[i]);
                }
                inodeAttrs = GetAttributesProvider().GetAttributes(elements, inodeAttrs);
            }
            return(inodeAttrs);
        }
示例#6
0
        /// <summary>create a directory at path specified by parent</summary>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
        private static INodesInPath UnprotectedMkdir(FSDirectory fsd, long inodeId, INodesInPath
                                                     parent, byte[] name, PermissionStatus permission, IList <AclEntry> aclEntries, long
                                                     timestamp)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            System.Diagnostics.Debug.Assert(parent.GetLastINode() != null);
            if (!parent.GetLastINode().IsDirectory())
            {
                throw new FileAlreadyExistsException("Parent path is not a directory: " + parent.
                                                     GetPath() + " " + DFSUtil.Bytes2String(name));
            }
            INodeDirectory dir = new INodeDirectory(inodeId, name, permission, timestamp);
            INodesInPath   iip = fsd.AddLastINode(parent, dir, true);

            if (iip != null && aclEntries != null)
            {
                AclStorage.UpdateINodeAcl(dir, aclEntries, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                          .CurrentStateId);
            }
            return(iip);
        }
示例#7
0
 /// <returns>null if the local name is null; otherwise, return the local name.</returns>
 public string GetLocalName()
 {
     byte[] name = GetLocalNameBytes();
     return(name == null ? null : DFSUtil.Bytes2String(name));
 }
示例#8
0
 public virtual string GetSymlinkString()
 {
     return(DFSUtil.Bytes2String(symlink));
 }
示例#9
0
 /// <summary>Get the string representation of the symlink.</summary>
 /// <returns>the symlink as a string.</returns>
 public string GetSymlink()
 {
     return(DFSUtil.Bytes2String(symlink));
 }
示例#10
0
 /// <summary>Get the string representation of the local name</summary>
 /// <returns>the local name in string</returns>
 public string GetLocalName()
 {
     return(DFSUtil.Bytes2String(path));
 }
示例#11
0
        /// <summary>Retrieve existing INodes from a path.</summary>
        /// <remarks>
        /// Retrieve existing INodes from a path. For non-snapshot path,
        /// the number of INodes is equal to the number of path components. For
        /// snapshot path (e.g., /foo/.snapshot/s1/bar), the number of INodes is
        /// (number_of_path_components - 1).
        /// An UnresolvedPathException is always thrown when an intermediate path
        /// component refers to a symbolic link. If the final path component refers
        /// to a symbolic link then an UnresolvedPathException is only thrown if
        /// resolveLink is true.
        /// <p>
        /// Example: <br />
        /// Given the path /c1/c2/c3 where only /c1/c2 exists, resulting in the
        /// following path components: ["","c1","c2","c3"]
        /// <p>
        /// <code>getExistingPathINodes(["","c1","c2"])</code> should fill
        /// the array with [rootINode,c1,c2], <br />
        /// <code>getExistingPathINodes(["","c1","c2","c3"])</code> should
        /// fill the array with [rootINode,c1,c2,null]
        /// </remarks>
        /// <param name="startingDir">the starting directory</param>
        /// <param name="components">array of path component name</param>
        /// <param name="resolveLink">
        /// indicates whether UnresolvedLinkException should
        /// be thrown when the path refers to a symbolic link.
        /// </param>
        /// <returns>the specified number of existing INodes in the path</returns>
        /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/>
        internal static Org.Apache.Hadoop.Hdfs.Server.Namenode.INodesInPath Resolve(INodeDirectory
                                                                                    startingDir, byte[][] components, bool resolveLink)
        {
            Preconditions.CheckArgument(startingDir.CompareTo(components[0]) == 0);
            INode curNode  = startingDir;
            int   count    = 0;
            int   inodeNum = 0;

            INode[] inodes     = new INode[components.Length];
            bool    isSnapshot = false;
            int     snapshotId = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId;

            while (count < components.Length && curNode != null)
            {
                bool lastComp = (count == components.Length - 1);
                inodes[inodeNum++] = curNode;
                bool           isRef = curNode.IsReference();
                bool           isDir = curNode.IsDirectory();
                INodeDirectory dir   = isDir ? curNode.AsDirectory() : null;
                if (!isRef && isDir && dir.IsWithSnapshot())
                {
                    //if the path is a non-snapshot path, update the latest snapshot.
                    if (!isSnapshot && ShouldUpdateLatestId(dir.GetDirectoryWithSnapshotFeature().GetLastSnapshotId
                                                                (), snapshotId))
                    {
                        snapshotId = dir.GetDirectoryWithSnapshotFeature().GetLastSnapshotId();
                    }
                }
                else
                {
                    if (isRef && isDir && !lastComp)
                    {
                        // If the curNode is a reference node, need to check its dstSnapshot:
                        // 1. if the existing snapshot is no later than the dstSnapshot (which
                        // is the latest snapshot in dst before the rename), the changes
                        // should be recorded in previous snapshots (belonging to src).
                        // 2. however, if the ref node is already the last component, we still
                        // need to know the latest snapshot among the ref node's ancestors,
                        // in case of processing a deletion operation. Thus we do not overwrite
                        // the latest snapshot if lastComp is true. In case of the operation is
                        // a modification operation, we do a similar check in corresponding
                        // recordModification method.
                        if (!isSnapshot)
                        {
                            int dstSnapshotId = curNode.AsReference().GetDstSnapshotId();
                            if (snapshotId == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId ||
                                (dstSnapshotId != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId &&
                                 dstSnapshotId >= snapshotId))
                            {
                                // no snapshot in dst tree of rename
                                // the above scenario
                                int lastSnapshot = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId;
                                DirectoryWithSnapshotFeature sf;
                                if (curNode.IsDirectory() && (sf = curNode.AsDirectory().GetDirectoryWithSnapshotFeature
                                                                       ()) != null)
                                {
                                    lastSnapshot = sf.GetLastSnapshotId();
                                }
                                snapshotId = lastSnapshot;
                            }
                        }
                    }
                }
                if (curNode.IsSymlink() && (!lastComp || resolveLink))
                {
                    string path      = ConstructPath(components, 0, components.Length);
                    string preceding = ConstructPath(components, 0, count);
                    string remainder = ConstructPath(components, count + 1, components.Length);
                    string link      = DFSUtil.Bytes2String(components[count]);
                    string target    = curNode.AsSymlink().GetSymlinkString();
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("UnresolvedPathException " + " path: " + path + " preceding: " + preceding
                                  + " count: " + count + " link: " + link + " target: " + target + " remainder: "
                                  + remainder);
                    }
                    throw new UnresolvedPathException(path, preceding, remainder, target);
                }
                if (lastComp || !isDir)
                {
                    break;
                }
                byte[] childName = components[count + 1];
                // check if the next byte[] in components is for ".snapshot"
                if (IsDotSnapshotDir(childName) && dir.IsSnapshottable())
                {
                    // skip the ".snapshot" in components
                    count++;
                    isSnapshot = true;
                    // check if ".snapshot" is the last element of components
                    if (count == components.Length - 1)
                    {
                        break;
                    }
                    // Resolve snapshot root
                    Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = dir.GetSnapshot(components
                                                                                                 [count + 1]);
                    if (s == null)
                    {
                        curNode = null;
                    }
                    else
                    {
                        // snapshot not found
                        curNode    = s.GetRoot();
                        snapshotId = s.GetId();
                    }
                }
                else
                {
                    // normal case, and also for resolving file/dir under snapshot root
                    curNode = dir.GetChild(childName, isSnapshot ? snapshotId : Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                           .CurrentStateId);
                }
                count++;
            }
            if (isSnapshot && !IsDotSnapshotDir(components[components.Length - 1]))
            {
                // for snapshot path shrink the inode array. however, for path ending with
                // .snapshot, still keep last the null inode in the array
                INode[] newNodes = new INode[components.Length - 1];
                System.Array.Copy(inodes, 0, newNodes, 0, newNodes.Length);
                inodes = newNodes;
            }
            return(new Org.Apache.Hadoop.Hdfs.Server.Namenode.INodesInPath(inodes, components
                                                                           , isSnapshot, snapshotId));
        }
示例#12
0
        /// <summary>Load a node stored in the created list from fsimage.</summary>
        /// <param name="createdNodeName">The name of the created node.</param>
        /// <param name="parent">The directory that the created list belongs to.</param>
        /// <returns>The created node.</returns>
        /// <exception cref="System.IO.IOException"/>
        public static INode LoadCreated(byte[] createdNodeName, INodeDirectory parent)
        {
            // the INode in the created list should be a reference to another INode
            // in posterior SnapshotDiffs or one of the current children
            foreach (DirectoryWithSnapshotFeature.DirectoryDiff postDiff in parent.GetDiffs())
            {
                INode d = postDiff.GetChildrenDiff().Search(Diff.ListType.Deleted, createdNodeName
                                                            );
                if (d != null)
                {
                    return(d);
                }
            }
            // else go to the next SnapshotDiff
            // use the current child
            INode currentChild = parent.GetChild(createdNodeName, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                 .CurrentStateId);

            if (currentChild == null)
            {
                throw new IOException("Cannot find an INode associated with the INode " + DFSUtil
                                      .Bytes2String(createdNodeName) + " in created list while loading FSImage.");
            }
            return(currentChild);
        }