Example #1
0
        public virtual QuotaCounts CleanDirectory(BlockStoragePolicySuite bsps, INodeDirectory
                                                  currentINode, int snapshot, int prior, INode.BlocksMapUpdateInfo collectedBlocks
                                                  , IList <INode> removedINodes)
        {
            QuotaCounts counts = new QuotaCounts.Builder().Build();
            IDictionary <INode, INode> priorCreated = null;
            IDictionary <INode, INode> priorDeleted = null;

            if (snapshot == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId)
            {
                // delete the current directory
                currentINode.RecordModification(prior);
                // delete everything in created list
                DirectoryWithSnapshotFeature.DirectoryDiff lastDiff = diffs.GetLast();
                if (lastDiff != null)
                {
                    counts.Add(lastDiff.diff.DestroyCreatedList(bsps, currentINode, collectedBlocks,
                                                                removedINodes));
                }
                counts.Add(currentINode.CleanSubtreeRecursively(bsps, snapshot, prior, collectedBlocks
                                                                , removedINodes, priorDeleted));
            }
            else
            {
                // update prior
                prior = GetDiffs().UpdatePrior(snapshot, prior);
                // if there is a snapshot diff associated with prior, we need to record
                // its original created and deleted list before deleting post
                if (prior != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId)
                {
                    DirectoryWithSnapshotFeature.DirectoryDiff priorDiff = this.GetDiffs().GetDiffById
                                                                               (prior);
                    if (priorDiff != null && priorDiff.GetSnapshotId() == prior)
                    {
                        IList <INode> cList = priorDiff.diff.GetList(Diff.ListType.Created);
                        IList <INode> dList = priorDiff.diff.GetList(Diff.ListType.Deleted);
                        priorCreated = CloneDiffList(cList);
                        priorDeleted = CloneDiffList(dList);
                    }
                }
                counts.Add(GetDiffs().DeleteSnapshotDiff(bsps, snapshot, prior, currentINode, collectedBlocks
                                                         , removedINodes));
                counts.Add(currentINode.CleanSubtreeRecursively(bsps, snapshot, prior, collectedBlocks
                                                                , removedINodes, priorDeleted));
                // check priorDiff again since it may be created during the diff deletion
                if (prior != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId)
                {
                    DirectoryWithSnapshotFeature.DirectoryDiff priorDiff = this.GetDiffs().GetDiffById
                                                                               (prior);
                    if (priorDiff != null && priorDiff.GetSnapshotId() == prior)
                    {
                        // For files/directories created between "prior" and "snapshot",
                        // we need to clear snapshot copies for "snapshot". Note that we must
                        // use null as prior in the cleanSubtree call. Files/directories that
                        // were created before "prior" will be covered by the later
                        // cleanSubtreeRecursively call.
                        if (priorCreated != null)
                        {
                            // we only check the node originally in prior's created list
                            foreach (INode cNode in priorDiff.GetChildrenDiff().GetList(Diff.ListType.Created
                                                                                        ))
                            {
                                if (priorCreated.Contains(cNode))
                                {
                                    counts.Add(cNode.CleanSubtree(bsps, snapshot, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                                  .NoSnapshotId, collectedBlocks, removedINodes));
                                }
                            }
                        }
                        // When a directory is moved from the deleted list of the posterior
                        // diff to the deleted list of this diff, we need to destroy its
                        // descendants that were 1) created after taking this diff and 2)
                        // deleted after taking posterior diff.
                        // For files moved from posterior's deleted list, we also need to
                        // delete its snapshot copy associated with the posterior snapshot.
                        foreach (INode dNode in priorDiff.GetChildrenDiff().GetList(Diff.ListType.Deleted
                                                                                    ))
                        {
                            if (priorDeleted == null || !priorDeleted.Contains(dNode))
                            {
                                counts.Add(CleanDeletedINode(bsps, dNode, snapshot, prior, collectedBlocks, removedINodes
                                                             ));
                            }
                        }
                    }
                }
            }
            if (currentINode.IsQuotaSet())
            {
                currentINode.GetDirectoryWithQuotaFeature().AddSpaceConsumed2Cache(counts.Negation
                                                                                       ());
            }
            return(counts);
        }