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 in...@apache.org on 2020/07/21 16:00:30 UTC
[hadoop] branch trunk updated: HDFS-15246.
ArrayIndexOfboundsException in BlockManager CreateLocatedBlock. Contributed
by Hemanth Boyina.
This is an automated email from the ASF dual-hosted git repository.
inigoiri pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 8b7695b HDFS-15246. ArrayIndexOfboundsException in BlockManager CreateLocatedBlock. Contributed by Hemanth Boyina.
8b7695b is described below
commit 8b7695bb2628574b4450bac19c12b29db9ee0628
Author: Inigo Goiri <in...@apache.org>
AuthorDate: Tue Jul 21 09:00:07 2020 -0700
HDFS-15246. ArrayIndexOfboundsException in BlockManager CreateLocatedBlock. Contributed by Hemanth Boyina.
---
.../hadoop/hdfs/server/namenode/FSDirRenameOp.java | 7 ++++-
.../hdfs/server/namenode/TestFileTruncate.java | 35 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java
index 602f996..a0c1e3a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java
@@ -650,7 +650,12 @@ class FSDirRenameOp {
// snapshot is taken on the dst tree, changes will be recorded in the
// latest snapshot of the src tree.
if (isSrcInSnapshot) {
- srcChild.recordModification(srcLatestSnapshotId);
+ if (srcChild.isFile()) {
+ INodeFile file = srcChild.asFile();
+ file.recordModification(srcLatestSnapshotId, true);
+ } else {
+ srcChild.recordModification(srcLatestSnapshotId);
+ }
}
// check srcChild for reference
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 7bfa8ae..eef1dba 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
@@ -37,6 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
@@ -67,6 +68,7 @@ import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.ToolRunner;
import org.slf4j.event.Level;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -1393,4 +1395,37 @@ public class TestFileTruncate {
fs.getQuotaUsage(root).getSpaceConsumed());
}
+
+ /**
+ * Test truncate on a snapshotted file.
+ */
+ @Test
+ public void testTruncatewithRenameandSnapshot() throws Exception {
+ final Path dir = new Path("/dir");
+ fs.mkdirs(dir, new FsPermission((short) 0777));
+ final Path file = new Path(dir, "file");
+ final Path movedFile = new Path("/file");
+
+ // 1. create a file and snapshot for dir which is having a file
+ DFSTestUtil.createFile(fs, file, 10, (short) 3, 0);
+ fs.allowSnapshot(dir);
+ Path snapshotPath = fs.createSnapshot(dir, "s0");
+ assertTrue(fs.exists(snapshotPath));
+
+ // 2. move the file
+ fs.rename(file, new Path("/"));
+
+ // 3.truncate the moved file
+ final boolean isReady = fs.truncate(movedFile, 5);
+ if (!isReady) {
+ checkBlockRecovery(movedFile);
+ }
+ FileStatus fileStatus = fs.getFileStatus(movedFile);
+ assertEquals(5, fileStatus.getLen());
+
+ // 4. get block locations of file which is in snapshot
+ LocatedBlocks locations = fs.getClient().getNamenode()
+ .getBlockLocations("/dir/.snapshot/s0/file", 0, 10);
+ assertEquals(10, locations.get(0).getBlockSize());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org