diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index 93d5c95c72..77d6bedc3a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -204,3 +204,6 @@ Branch-2802 Snapshot (Unreleased) HDFS-4534. Add INodeReference in order to support rename with snapshots. (szetszwo) + + HDFS-4616. Update the FilesDeleted metric while deleting file/dir in the + current tree. (Jing Zhao via szetszwo) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java index 238f35fd73..b0a4be2bc0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java @@ -647,8 +647,10 @@ public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior, throws QuotaExceededException { if (prior == null && snapshot == null) { // destroy the whole subtree and collect blocks that should be deleted + Quota.Counts counts = Quota.Counts.newInstance(); + this.computeQuotaUsage(counts, true); destroyAndCollectBlocks(collectedBlocks); - return Quota.Counts.newInstance(); + return counts; } else { // process recursively down the subtree Quota.Counts counts = cleanSubtreeRecursively(snapshot, prior, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java index 7fb0601525..cbe55830f4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java @@ -293,11 +293,13 @@ public void setBlocks(BlockInfo[] blocks) { public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior, final BlocksMapUpdateInfo collectedBlocks) throws QuotaExceededException { + Quota.Counts counts = Quota.Counts.newInstance(); if (snapshot == null && prior == null) { // this only happens when deleting the current file + computeQuotaUsage(counts, false); destroyAndCollectBlocks(collectedBlocks); } - return Quota.Counts.newInstance(); + return counts; } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java index f0f1aacbeb..0106ba8955 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeSymlink.java @@ -74,7 +74,7 @@ public byte[] getSymlink() { @Override public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior, final BlocksMapUpdateInfo collectedBlocks) { - return Quota.Counts.newInstance(); + return Quota.Counts.newInstance(1, 0); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java index 0bb637f626..cca1ee69b7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java @@ -89,16 +89,19 @@ private final boolean removeCreatedChild(final int c, final INode child) { } /** clear the created list */ - private void destroyCreatedList( + private Quota.Counts destroyCreatedList( final INodeDirectoryWithSnapshot currentINode, final BlocksMapUpdateInfo collectedBlocks) { + Quota.Counts counts = Quota.Counts.newInstance(); final List createdList = getList(ListType.CREATED); for (INode c : createdList) { + c.computeQuotaUsage(counts, true); c.destroyAndCollectBlocks(collectedBlocks); // c should be contained in the children list, remove it currentINode.removeChild(c); } createdList.clear(); + return counts; } /** clear the deleted list */ @@ -659,7 +662,7 @@ public Quota.Counts cleanSubtree(final Snapshot snapshot, Snapshot prior, // delete everything in created list DirectoryDiff lastDiff = diffs.getLast(); if (lastDiff != null) { - lastDiff.diff.destroyCreatedList(this, collectedBlocks); + counts.add(lastDiff.diff.destroyCreatedList(this, collectedBlocks)); } } else { // update prior