예제 #1
0
            /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
            internal RenameOperation(FSDirectory fsd, string src, string dst, INodesInPath srcIIP
                                     , INodesInPath dstIIP)
            {
                this.fsd          = fsd;
                this.src          = src;
                this.dst          = dst;
                this.srcIIP       = srcIIP;
                this.dstIIP       = dstIIP;
                this.srcParentIIP = srcIIP.GetParentINodesInPath();
                this.dstParentIIP = dstIIP.GetParentINodesInPath();
                BlockStoragePolicySuite bsps = fsd.GetBlockStoragePolicySuite();

                srcChild     = this.srcIIP.GetLastINode();
                srcChildName = srcChild.GetLocalNameBytes();
                int srcLatestSnapshotId = srcIIP.GetLatestSnapshotId();

                isSrcInSnapshot     = srcChild.IsInLatestSnapshot(srcLatestSnapshotId);
                srcChildIsReference = srcChild.IsReference();
                srcParent           = this.srcIIP.GetINode(-2).AsDirectory();
                // Record the snapshot on srcChild. After the rename, before any new
                // snapshot is taken on the dst tree, changes will be recorded in the
                // latest snapshot of the src tree.
                if (isSrcInSnapshot)
                {
                    srcChild.RecordModification(srcLatestSnapshotId);
                }
                // check srcChild for reference
                srcRefDstSnapshot = srcChildIsReference ? srcChild.AsReference().GetDstSnapshotId
                                        () : Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId;
                oldSrcCounts = new QuotaCounts.Builder().Build();
                if (isSrcInSnapshot)
                {
                    INodeReference.WithName withName = srcParent.ReplaceChild4ReferenceWithName(srcChild
                                                                                                , srcLatestSnapshotId);
                    withCount   = (INodeReference.WithCount)withName.GetReferredINode();
                    srcChild    = withName;
                    this.srcIIP = INodesInPath.Replace(srcIIP, srcIIP.Length() - 1, srcChild);
                    // get the counts before rename
                    withCount.GetReferredINode().ComputeQuotaUsage(bsps, oldSrcCounts, true);
                }
                else
                {
                    if (srcChildIsReference)
                    {
                        // srcChild is reference but srcChild is not in latest snapshot
                        withCount = (INodeReference.WithCount)srcChild.AsReference().GetReferredINode();
                    }
                    else
                    {
                        withCount = null;
                    }
                }
            }
예제 #2
0
        /// <summary>
        /// Delete a path from the name space
        /// Update the count at each ancestor directory with quota
        /// </summary>
        /// <param name="iip">the inodes resolved from the path</param>
        /// <param name="collectedBlocks">blocks collected from the deleted path</param>
        /// <param name="removedINodes">inodes that should be removed from inodeMap</param>
        /// <param name="mtime">the time the inode is removed</param>
        /// <returns>the number of inodes deleted; 0 if no inodes are deleted.</returns>
        private static long UnprotectedDelete(FSDirectory fsd, INodesInPath iip, INode.BlocksMapUpdateInfo
                                              collectedBlocks, IList <INode> removedINodes, long mtime)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            // check if target node exists
            INode targetNode = iip.GetLastINode();

            if (targetNode == null)
            {
                return(-1);
            }
            // record modification
            int latestSnapshot = iip.GetLatestSnapshotId();

            targetNode.RecordModification(latestSnapshot);
            // Remove the node from the namespace
            long removed = fsd.RemoveLastINode(iip);

            if (removed == -1)
            {
                return(-1);
            }
            // set the parent's modification time
            INodeDirectory parent = targetNode.GetParent();

            parent.UpdateModificationTime(mtime, latestSnapshot);
            fsd.UpdateCountForDelete(targetNode, iip);
            if (removed == 0)
            {
                return(0);
            }
            // collect block and update quota
            if (!targetNode.IsInLatestSnapshot(latestSnapshot))
            {
                targetNode.DestroyAndCollectBlocks(fsd.GetBlockStoragePolicySuite(), collectedBlocks
                                                   , removedINodes);
            }
            else
            {
                QuotaCounts counts = targetNode.CleanSubtree(fsd.GetBlockStoragePolicySuite(), Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                             .CurrentStateId, latestSnapshot, collectedBlocks, removedINodes);
                removed = counts.GetNameSpace();
                fsd.UpdateCountNoQuotaCheck(iip, iip.Length() - 1, counts.Negation());
            }
            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* FSDirectory.unprotectedDelete: " + iip.GetPath
                                                  () + " is removed");
            }
            return(removed);
        }
예제 #3
0
            /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
            internal virtual bool CleanDst(BlockStoragePolicySuite bsps, INode.BlocksMapUpdateInfo
                                           collectedBlocks)
            {
                Preconditions.CheckState(oldDstChild != null);
                IList <INode> removedINodes = new ChunkedArrayList <INode>();
                bool          filesDeleted;

                if (!oldDstChild.IsInLatestSnapshot(dstIIP.GetLatestSnapshotId()))
                {
                    oldDstChild.DestroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
                    filesDeleted = true;
                }
                else
                {
                    filesDeleted = oldDstChild.CleanSubtree(bsps, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                            .CurrentStateId, dstIIP.GetLatestSnapshotId(), collectedBlocks, removedINodes).GetNameSpace
                                       () >= 0;
                }
                fsd.GetFSNamesystem().RemoveLeasesAndINodes(src, removedINodes, false);
                return(filesDeleted);
            }
예제 #4
0
        /// <exception cref="System.IO.IOException"/>
        private static INodeFile[] VerifySrcFiles(FSDirectory fsd, string[] srcs, INodesInPath
                                                  targetIIP, FSPermissionChecker pc)
        {
            // to make sure no two files are the same
            ICollection <INodeFile> si  = new LinkedHashSet <INodeFile>();
            INodeFile      targetINode  = targetIIP.GetLastINode().AsFile();
            INodeDirectory targetParent = targetINode.GetParent();

            // now check the srcs
            foreach (string src in srcs)
            {
                INodesInPath iip = fsd.GetINodesInPath4Write(src);
                // permission check for srcs
                if (pc != null)
                {
                    fsd.CheckPathAccess(pc, iip, FsAction.Read);
                    // read the file
                    fsd.CheckParentAccess(pc, iip, FsAction.Write);
                }
                // for delete
                INode     srcINode     = iip.GetLastINode();
                INodeFile srcINodeFile = INodeFile.ValueOf(srcINode, src);
                // make sure the src file and the target file are in the same dir
                if (srcINodeFile.GetParent() != targetParent)
                {
                    throw new HadoopIllegalArgumentException("Source file " + src + " is not in the same directory with the target "
                                                             + targetIIP.GetPath());
                }
                // make sure all the source files are not in snapshot
                if (srcINode.IsInLatestSnapshot(iip.GetLatestSnapshotId()))
                {
                    throw new SnapshotException("Concat: the source file " + src + " is in snapshot");
                }
                // check if the file has other references.
                if (srcINode.IsReference() && ((INodeReference.WithCount)srcINode.AsReference().GetReferredINode
                                                   ()).GetReferenceCount() > 1)
                {
                    throw new SnapshotException("Concat: the source file " + src + " is referred by some other reference in some snapshot."
                                                );
                }
                // source file cannot be the same with the target file
                if (srcINode == targetINode)
                {
                    throw new HadoopIllegalArgumentException("concat: the src file " + src + " is the same with the target file "
                                                             + targetIIP.GetPath());
                }
                // source file cannot be under construction or empty
                if (srcINodeFile.IsUnderConstruction() || srcINodeFile.NumBlocks() == 0)
                {
                    throw new HadoopIllegalArgumentException("concat: source file " + src + " is invalid or empty or underConstruction"
                                                             );
                }
                // source file's preferred block size cannot be greater than the target
                // file
                if (srcINodeFile.GetPreferredBlockSize() > targetINode.GetPreferredBlockSize())
                {
                    throw new HadoopIllegalArgumentException("concat: source file " + src + " has preferred block size "
                                                             + srcINodeFile.GetPreferredBlockSize() + " which is greater than the target file's preferred block size "
                                                             + targetINode.GetPreferredBlockSize());
                }
                si.AddItem(srcINodeFile);
            }
            // make sure no two files are the same
            if (si.Count < srcs.Length)
            {
                // it means at least two files are the same
                throw new HadoopIllegalArgumentException("concat: at least two of the source files are the same"
                                                         );
            }
            return(Sharpen.Collections.ToArray(si, new INodeFile[si.Count]));
        }