From b91fda7f1dcbd62b8e44cf3b28e9be5fa3b3871f Mon Sep 17 00:00:00 2001 From: He Xiaoqiao Date: Wed, 11 Dec 2019 16:33:26 -0800 Subject: [PATCH] HDFS-15050. Optimize log information when DFSInputStream meet CannotObtainBlockLengthException. Contributed by Xiaoqiao He. Signed-off-by: Wei-Chiu Chuang (cherry picked from commit 99af49878cc47f5750b6c0edadc8a4c2fcd7a7c6) (cherry picked from commit 8ba4e13dcc4ad16e8483d33a31ed52e1b8d4e686) (cherry picked from commit 974706c5fdd7c875922b38a2efffb6b7bda8cdf5) --- .../hdfs/CannotObtainBlockLengthException.java | 12 ++++++++++++ .../java/org/apache/hadoop/hdfs/DFSInputStream.java | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/CannotObtainBlockLengthException.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/CannotObtainBlockLengthException.java index 6da1d67b9ae..d6b2856a125 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/CannotObtainBlockLengthException.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/CannotObtainBlockLengthException.java @@ -52,4 +52,16 @@ public class CannotObtainBlockLengthException extends IOException { super("Cannot obtain block length for " + locatedBlock); } + /** + * Constructs an {@code CannotObtainBlockLengthException} with the + * specified LocatedBlock and file that failed to obtain block length. + * + * @param locatedBlock + * The LocatedBlock instance which block length can not be obtained + * @param src The file which include this block + */ + public CannotObtainBlockLengthException(LocatedBlock locatedBlock, + String src) { + super("Cannot obtain block length for " + locatedBlock + " of " + src); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java index 735d124dfaf..939c45c7a97 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java @@ -451,7 +451,7 @@ public class DFSInputStream extends FSInputStream return 0; } - throw new CannotObtainBlockLengthException(locatedblock); + throw new CannotObtainBlockLengthException(locatedblock, src); } public long getFileLength() {