Пример #1
0
        /// <summary>
        /// Remove the snapshot with the given name from
        /// <see cref="snapshotsByNames"/>
        /// ,
        /// and delete all the corresponding DirectoryDiff.
        /// </summary>
        /// <param name="snapshotRoot">The directory where we take snapshots</param>
        /// <param name="snapshotName">The name of the snapshot to be removed</param>
        /// <param name="collectedBlocks">Used to collect information to update blocksMap</param>
        /// <returns>
        /// The removed snapshot. Null if no snapshot with the given name
        /// exists.
        /// </returns>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException"/>
        public virtual Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot RemoveSnapshot
            (BlockStoragePolicySuite bsps, INodeDirectory snapshotRoot, string snapshotName,
            INode.BlocksMapUpdateInfo collectedBlocks, IList <INode> removedINodes)
        {
            int i = SearchSnapshot(DFSUtil.String2Bytes(snapshotName));

            if (i < 0)
            {
                throw new SnapshotException("Cannot delete snapshot " + snapshotName + " from path "
                                            + snapshotRoot.GetFullPathName() + ": the snapshot does not exist.");
            }
            else
            {
                Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = snapshotsByNames
                                                                                    [i];
                int prior = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.FindLatestSnapshot
                                (snapshotRoot, snapshot.GetId());
                try
                {
                    QuotaCounts counts = snapshotRoot.CleanSubtree(bsps, snapshot.GetId(), prior, collectedBlocks
                                                                   , removedINodes);
                    INodeDirectory parent = snapshotRoot.GetParent();
                    if (parent != null)
                    {
                        // there will not be any WithName node corresponding to the deleted
                        // snapshot, thus only update the quota usage in the current tree
                        parent.AddSpaceConsumed(counts.Negation(), true);
                    }
                }
                catch (QuotaExceededException e)
                {
                    INode.Log.Error("BUG: removeSnapshot increases namespace usage.", e);
                }
                // remove from snapshotsByNames after successfully cleaning the subtree
                snapshotsByNames.Remove(i);
                return(snapshot);
            }
        }