You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by we...@apache.org on 2021/04/02 06:07:05 UTC
[hadoop] 04/05: HDFS-15332. Quota Space consumed was wrong in
truncate with Snapshots. Contributed by hemanthboyina.
This is an automated email from the ASF dual-hosted git repository.
weichiu pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit 1148d3895f140465d199025d886dc87dcc411282
Author: Inigo Goiri <in...@apache.org>
AuthorDate: Wed May 6 13:18:32 2020 -0700
HDFS-15332. Quota Space consumed was wrong in truncate with Snapshots. Contributed by hemanthboyina.
(cherry picked from commit 130f89e068ca346a44fa6619ae0726c1e5cc5d06)
---
.../namenode/snapshot/FileWithSnapshotFeature.java | 6 ++++
.../hdfs/server/namenode/TestFileTruncate.java | 40 ++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java
index 7fa7ce7..44c258c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/FileWithSnapshotFeature.java
@@ -163,6 +163,12 @@ public class FileWithSnapshotFeature implements INode.Feature {
if (removed.getBlocks() != null) {
allBlocks.addAll(Arrays.asList(removed.getBlocks()));
}
+ for (FileDiff diff : diffs) {
+ BlockInfo[] diffBlocks = diff.getBlocks();
+ if (diffBlocks != null) {
+ allBlocks.addAll(Arrays.asList(diffBlocks));
+ }
+ }
for (BlockInfo b: allBlocks) {
short replication = b.getReplication();
long blockSize = b.isComplete() ? b.getNumBytes() : file
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java
index 0964b3e..335772b 100755
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java
@@ -1420,4 +1420,44 @@ public class TestFileTruncate {
fs.concat(trg, srcs);
assertEquals(1, fs.getContentSummary(new Path(dir)).getFileCount());
}
+
+ /**
+ * Test Quota space consumed with multiple snapshots.
+ */
+ @Test
+ public void testQuotaSpaceConsumedWithSnapshots() throws IOException {
+ Path root = new Path("/");
+ Path dir = new Path(root, "dir");
+ fs.mkdirs(dir);
+ fs.allowSnapshot(dir);
+
+ // create a file
+ Path file2 = new Path(dir, "file2");
+ DFSTestUtil.createFile(fs, file2, 30, (short) 1, 0);
+
+ // create a snapshot and truncate the file
+ fs.createSnapshot(dir, "s1");
+ boolean isReady = fs.truncate(file2, 20);
+ if (!isReady) {
+ checkBlockRecovery(file2);
+ }
+
+ // create one more snapshot and truncate the file which exists in previous
+ // snapshot
+ fs.createSnapshot(dir, "s2");
+ isReady = fs.truncate(file2, 10);
+ if (!isReady) {
+ checkBlockRecovery(file2);
+ }
+
+ // delete the snapshots and check quota space consumed usage
+ fs.deleteSnapshot(dir, "s1");
+ fs.deleteSnapshot(dir, "s2");
+ assertEquals(fs.getContentSummary(root).getSpaceConsumed(),
+ fs.getQuotaUsage(root).getSpaceConsumed());
+ fs.delete(dir, true);
+ assertEquals(fs.getContentSummary(root).getSpaceConsumed(),
+ fs.getQuotaUsage(root).getSpaceConsumed());
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org