Esempio n. 1
0
        /// <summary>
        /// Delete a path from the name space
        /// Update the count at each ancestor directory with quota
        /// <br />
        /// Note: This is to be used by
        /// <see cref="FSEditLog"/>
        /// only.
        /// <br />
        /// </summary>
        /// <param name="src">a string representation of a path to an inode</param>
        /// <param name="mtime">the time the inode is removed</param>
        /// <exception cref="System.IO.IOException"/>
        internal static void DeleteForEditLog(FSDirectory fsd, string src, long mtime)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            FSNamesystem fsn = fsd.GetFSNamesystem();

            INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo();
            IList <INode>             removedINodes   = new ChunkedArrayList <INode>();
            INodesInPath iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), false
                                                         );

            if (!DeleteAllowed(iip, src))
            {
                return;
            }
            IList <INodeDirectory> snapshottableDirs = new AList <INodeDirectory>();

            FSDirSnapshotOp.CheckSnapshot(iip.GetLastINode(), snapshottableDirs);
            long filesRemoved = UnprotectedDelete(fsd, iip, collectedBlocks, removedINodes, mtime
                                                  );

            fsn.RemoveSnapshottableDirs(snapshottableDirs);
            if (filesRemoved >= 0)
            {
                fsn.RemoveLeasesAndINodes(src, removedINodes, false);
                fsn.RemoveBlocksAndUpdateSafemodeTotal(collectedBlocks);
            }
        }
Esempio n. 2
0
        /// <summary>Delete the target directory and collect the blocks under it</summary>
        /// <param name="iip">the INodesInPath instance containing all the INodes for the path
        ///     </param>
        /// <param name="collectedBlocks">Blocks under the deleted directory</param>
        /// <param name="removedINodes">INodes that should be removed from inodeMap</param>
        /// <returns>the number of files that have been removed</returns>
        /// <exception cref="System.IO.IOException"/>
        internal static long Delete(FSDirectory fsd, INodesInPath iip, INode.BlocksMapUpdateInfo
                                    collectedBlocks, IList <INode> removedINodes, long mtime)
        {
            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* FSDirectory.delete: " + iip.GetPath());
            }
            long filesRemoved;

            fsd.WriteLock();
            try
            {
                if (!DeleteAllowed(iip, iip.GetPath()))
                {
                    filesRemoved = -1;
                }
                else
                {
                    IList <INodeDirectory> snapshottableDirs = new AList <INodeDirectory>();
                    FSDirSnapshotOp.CheckSnapshot(iip.GetLastINode(), snapshottableDirs);
                    filesRemoved = UnprotectedDelete(fsd, iip, collectedBlocks, removedINodes, mtime);
                    fsd.GetFSNamesystem().RemoveSnapshottableDirs(snapshottableDirs);
                }
            }
            finally
            {
                fsd.WriteUnlock();
            }
            return(filesRemoved);
        }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"/>
        private static void ValidateRenameSource(INodesInPath srcIIP)
        {
            string error;
            INode  srcInode = srcIIP.GetLastINode();

            // validate source
            if (srcInode == null)
            {
                error = "rename source " + srcIIP.GetPath() + " is not found.";
                NameNode.stateChangeLog.Warn("DIR* FSDirectory.unprotectedRenameTo: " + error);
                throw new FileNotFoundException(error);
            }
            if (srcIIP.Length() == 1)
            {
                error = "rename source cannot be the root";
                NameNode.stateChangeLog.Warn("DIR* FSDirectory.unprotectedRenameTo: " + error);
                throw new IOException(error);
            }
            // srcInode and its subtree cannot contain snapshottable directories with
            // snapshots
            FSDirSnapshotOp.CheckSnapshot(srcInode, null);
        }
Esempio n. 4
0
        /// <summary>Rename src to dst.</summary>
        /// <remarks>
        /// Rename src to dst.
        /// See
        /// <see cref="Org.Apache.Hadoop.Hdfs.DistributedFileSystem.Rename(Org.Apache.Hadoop.FS.Path, Org.Apache.Hadoop.FS.Path, Org.Apache.Hadoop.FS.Options.Rename[])
        ///     "/>
        /// for details related to rename semantics and exceptions.
        /// </remarks>
        /// <param name="fsd">FSDirectory</param>
        /// <param name="src">source path</param>
        /// <param name="dst">destination path</param>
        /// <param name="timestamp">modification time</param>
        /// <param name="collectedBlocks">blocks to be removed</param>
        /// <param name="options">Rename options</param>
        /// <returns>whether a file/directory gets overwritten in the dst path</returns>
        /// <exception cref="System.IO.IOException"/>
        internal static bool UnprotectedRenameTo(FSDirectory fsd, string src, string dst,
                                                 INodesInPath srcIIP, INodesInPath dstIIP, long timestamp, INode.BlocksMapUpdateInfo
                                                 collectedBlocks, params Options.Rename[] options)
        {
            System.Diagnostics.Debug.Assert(fsd.HasWriteLock());
            bool overwrite = options != null && Arrays.AsList(options).Contains(Options.Rename
                                                                                .Overwrite);
            string error;
            INode  srcInode = srcIIP.GetLastINode();

            ValidateRenameSource(srcIIP);
            // validate the destination
            if (dst.Equals(src))
            {
                throw new FileAlreadyExistsException("The source " + src + " and destination " +
                                                     dst + " are the same");
            }
            ValidateDestination(src, dst, srcInode);
            if (dstIIP.Length() == 1)
            {
                error = "rename destination cannot be the root";
                NameNode.stateChangeLog.Warn("DIR* FSDirectory.unprotectedRenameTo: " + error);
                throw new IOException(error);
            }
            BlockStoragePolicySuite bsps = fsd.GetBlockStoragePolicySuite();

            fsd.ezManager.CheckMoveValidity(srcIIP, dstIIP, src);
            INode dstInode = dstIIP.GetLastINode();
            IList <INodeDirectory> snapshottableDirs = new AList <INodeDirectory>();

            if (dstInode != null)
            {
                // Destination exists
                ValidateOverwrite(src, dst, overwrite, srcInode, dstInode);
                FSDirSnapshotOp.CheckSnapshot(dstInode, snapshottableDirs);
            }
            INode dstParent = dstIIP.GetINode(-2);

            if (dstParent == null)
            {
                error = "rename destination parent " + dst + " not found.";
                NameNode.stateChangeLog.Warn("DIR* FSDirectory.unprotectedRenameTo: " + error);
                throw new FileNotFoundException(error);
            }
            if (!dstParent.IsDirectory())
            {
                error = "rename destination parent " + dst + " is a file.";
                NameNode.stateChangeLog.Warn("DIR* FSDirectory.unprotectedRenameTo: " + error);
                throw new ParentNotDirectoryException(error);
            }
            // Ensure dst has quota to accommodate rename
            VerifyFsLimitsForRename(fsd, srcIIP, dstIIP);
            VerifyQuotaForRename(fsd, srcIIP, dstIIP);
            FSDirRenameOp.RenameOperation tx = new FSDirRenameOp.RenameOperation(fsd, src, dst
                                                                                 , srcIIP, dstIIP);
            bool undoRemoveSrc = true;

            tx.RemoveSrc();
            bool undoRemoveDst = false;
            long removedNum    = 0;

            try
            {
                if (dstInode != null)
                {
                    // dst exists, remove it
                    removedNum = tx.RemoveDst();
                    if (removedNum != -1)
                    {
                        undoRemoveDst = true;
                    }
                }
                // add src as dst to complete rename
                if (tx.AddSourceToDestination())
                {
                    undoRemoveSrc = false;
                    if (NameNode.stateChangeLog.IsDebugEnabled())
                    {
                        NameNode.stateChangeLog.Debug("DIR* FSDirectory.unprotectedRenameTo: " + src + " is renamed to "
                                                      + dst);
                    }
                    tx.UpdateMtimeAndLease(timestamp);
                    // Collect the blocks and remove the lease for previous dst
                    bool filesDeleted = false;
                    if (undoRemoveDst)
                    {
                        undoRemoveDst = false;
                        if (removedNum > 0)
                        {
                            filesDeleted = tx.CleanDst(bsps, collectedBlocks);
                        }
                    }
                    if (snapshottableDirs.Count > 0)
                    {
                        // There are snapshottable directories (without snapshots) to be
                        // deleted. Need to update the SnapshotManager.
                        fsd.GetFSNamesystem().RemoveSnapshottableDirs(snapshottableDirs);
                    }
                    tx.UpdateQuotasInSourceTree(bsps);
                    return(filesDeleted);
                }
            }
            finally
            {
                if (undoRemoveSrc)
                {
                    tx.RestoreSource();
                }
                if (undoRemoveDst)
                {
                    // Rename failed - restore dst
                    tx.RestoreDst(bsps);
                }
            }
            NameNode.stateChangeLog.Warn("DIR* FSDirectory.unprotectedRenameTo: " + "failed to rename "
                                         + src + " to " + dst);
            throw new IOException("rename from " + src + " to " + dst + " failed.");
        }