/// <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); } }
/// <summary>Remove a file/directory from the namespace.</summary> /// <remarks> /// Remove a file/directory from the namespace. /// <p> /// For large directories, deletion is incremental. The blocks under /// the directory are collected and deleted a small number at a time holding /// the /// <see cref="FSNamesystem"/> /// lock. /// <p> /// For small directory or file the deletion is done in one shot. /// </remarks> /// <exception cref="System.IO.IOException"/> internal static INode.BlocksMapUpdateInfo DeleteInternal(FSNamesystem fsn, string src, INodesInPath iip, bool logRetryCache) { System.Diagnostics.Debug.Assert(fsn.HasWriteLock()); if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* NameSystem.delete: " + src); } FSDirectory fsd = fsn.GetFSDirectory(); INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo(); IList <INode> removedINodes = new ChunkedArrayList <INode>(); long mtime = Time.Now(); // Unlink the target directory from directory tree long filesRemoved = Delete(fsd, iip, collectedBlocks, removedINodes, mtime); if (filesRemoved < 0) { return(null); } fsd.GetEditLog().LogDelete(src, mtime, logRetryCache); IncrDeletedFileCount(filesRemoved); fsn.RemoveLeasesAndINodes(src, removedINodes, true); if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* Namesystem.delete: " + src + " is removed"); } return(collectedBlocks); }
/// <summary>Delete a snapshot of a snapshottable directory</summary> /// <param name="snapshotRoot">The snapshottable directory</param> /// <param name="snapshotName">The name of the to-be-deleted snapshot</param> /// <exception cref="System.IO.IOException"/> internal static INode.BlocksMapUpdateInfo DeleteSnapshot(FSDirectory fsd, SnapshotManager snapshotManager, string snapshotRoot, string snapshotName, bool logRetryCache) { INodesInPath iip = fsd.GetINodesInPath4Write(snapshotRoot); if (fsd.IsPermissionEnabled()) { FSPermissionChecker pc = fsd.GetPermissionChecker(); fsd.CheckOwner(pc, iip); } INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo(); ChunkedArrayList <INode> removedINodes = new ChunkedArrayList <INode>(); fsd.WriteLock(); try { snapshotManager.DeleteSnapshot(iip, snapshotName, collectedBlocks, removedINodes); fsd.RemoveFromInodeMap(removedINodes); } finally { fsd.WriteUnlock(); } removedINodes.Clear(); fsd.GetEditLog().LogDeleteSnapshot(snapshotRoot, snapshotName, logRetryCache); return(collectedBlocks); }
/// <summary> /// Returns a list of blocks on a datanode that are insufficiently /// replicated, i.e. /// </summary> /// <remarks> /// Returns a list of blocks on a datanode that are insufficiently /// replicated, i.e. are under-replicated enough to prevent decommission. /// <p/> /// As part of this, it also schedules replication work for /// any under-replicated blocks. /// </remarks> /// <param name="datanode"/> /// <returns>List of insufficiently replicated blocks</returns> private AbstractList <BlockInfoContiguous> HandleInsufficientlyReplicated(DatanodeDescriptor datanode) { AbstractList <BlockInfoContiguous> insufficient = new ChunkedArrayList <BlockInfoContiguous >(); this.ProcessBlocksForDecomInternal(datanode, datanode.GetBlockIterator(), insufficient , false); return(insufficient); }
/// <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); }