hadoop git commit: HDFS-13813. Exit NameNode if dangling child inode is detected when saving FsImage. Contributed by Siyao Meng.

2018-08-13 Thread weichiu
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.9 59031be4c -> 584d6a9e8


HDFS-13813. Exit NameNode if dangling child inode is detected when saving 
FsImage. Contributed by Siyao Meng.

(cherry picked from commit 23854443efa62aa70a1c30c32c3816750e5d7a5b)
(cherry picked from commit b38649c59a70b3112811443464b3b3180f4b9873)
(cherry picked from commit 4b606eb9fd5dde5629e791d3338886a70b5aa57c)
(cherry picked from commit ad5c3300ff7383d84ca764283e876a3889846269)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/584d6a9e
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/584d6a9e
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/584d6a9e

Branch: refs/heads/branch-2.9
Commit: 584d6a9e854c117ae08bd2122dc22b94087012ed
Parents: 59031be
Author: Wei-Chiu Chuang 
Authored: Mon Aug 13 16:12:37 2018 -0700
Committer: Wei-Chiu Chuang 
Committed: Mon Aug 13 17:09:36 2018 -0700

--
 .../server/namenode/FSImageFormatPBINode.java   | 28 ++--
 .../server/namenode/FSImageFormatProtobuf.java  |  9 ---
 2 files changed, 32 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/584d6a9e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
index 80879b0..ed87d05 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
@@ -407,6 +407,8 @@ public final class FSImageFormatPBINode {
   }
 
   public final static class Saver {
+private long numImageErrors;
+
 private static long buildPermissionStatus(INodeAttributes n,
 final SaverContext.DeduplicationMap stringMap) {
   long userId = stringMap.getId(n.getUserName());
@@ -525,11 +527,13 @@ public final class FSImageFormatPBINode {
   this.summary = summary;
   this.context = parent.getContext();
   this.fsn = context.getSourceNamesystem();
+  this.numImageErrors = 0;
 }
 
 void serializeINodeDirectorySection(OutputStream out) throws IOException {
-  Iterator iter = fsn.getFSDirectory()
-  .getINodeMap().getMapIterator();
+  FSDirectory dir = fsn.getFSDirectory();
+  Iterator iter = dir.getINodeMap()
+  .getMapIterator();
   final ArrayList refList = parent.getSaverContext()
   .getRefList();
   int i = 0;
@@ -545,6 +549,17 @@ public final class FSImageFormatPBINode {
   INodeDirectorySection.DirEntry.Builder b = INodeDirectorySection.
   DirEntry.newBuilder().setParent(n.getId());
   for (INode inode : children) {
+// Error if the child inode doesn't exist in inodeMap
+if (dir.getInode(inode.getId()) == null) {
+  FSImage.LOG.error(
+  "FSImageFormatPBINode#serializeINodeDirectorySection: " +
+  "Dangling child pointer found. Missing INode in " +
+  "inodeMap: id=" + inode.getId() +
+  "; path=" + inode.getFullPathName() +
+  "; parent=" + (inode.getParent() == null ? "null" :
+  inode.getParent().getFullPathName()));
+  ++numImageErrors;
+}
 if (!inode.isReference()) {
   b.addChildren(inode.getId());
 } else {
@@ -672,6 +687,15 @@ public final class FSImageFormatPBINode {
   .setId(n.getId())
   .setName(ByteString.copyFrom(n.getLocalNameBytes()));
 }
+
+/**
+ * Number of non-fatal errors detected while writing the
+ * INodeSection and INodeDirectorySection sections.
+ * @return the number of non-fatal errors detected.
+ */
+public long getNumImageErrors() {
+  return numImageErrors;
+}
   }
 
   private FSImageFormatPBINode() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/584d6a9e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
index 718f0ec..6a7b9db 100644
--- 

hadoop git commit: HDFS-13813. Exit NameNode if dangling child inode is detected when saving FsImage. Contributed by Siyao Meng.

2018-08-13 Thread weichiu
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 305b9a652 -> ad5c3300f


HDFS-13813. Exit NameNode if dangling child inode is detected when saving 
FsImage. Contributed by Siyao Meng.

(cherry picked from commit 23854443efa62aa70a1c30c32c3816750e5d7a5b)
(cherry picked from commit b38649c59a70b3112811443464b3b3180f4b9873)
(cherry picked from commit 4b606eb9fd5dde5629e791d3338886a70b5aa57c)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ad5c3300
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ad5c3300
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ad5c3300

Branch: refs/heads/branch-2
Commit: ad5c3300ff7383d84ca764283e876a3889846269
Parents: 305b9a6
Author: Wei-Chiu Chuang 
Authored: Mon Aug 13 16:12:37 2018 -0700
Committer: Wei-Chiu Chuang 
Committed: Mon Aug 13 16:15:36 2018 -0700

--
 .../server/namenode/FSImageFormatPBINode.java   | 28 ++--
 .../server/namenode/FSImageFormatProtobuf.java  |  9 ---
 2 files changed, 32 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ad5c3300/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
index 80879b0..ed87d05 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
@@ -407,6 +407,8 @@ public final class FSImageFormatPBINode {
   }
 
   public final static class Saver {
+private long numImageErrors;
+
 private static long buildPermissionStatus(INodeAttributes n,
 final SaverContext.DeduplicationMap stringMap) {
   long userId = stringMap.getId(n.getUserName());
@@ -525,11 +527,13 @@ public final class FSImageFormatPBINode {
   this.summary = summary;
   this.context = parent.getContext();
   this.fsn = context.getSourceNamesystem();
+  this.numImageErrors = 0;
 }
 
 void serializeINodeDirectorySection(OutputStream out) throws IOException {
-  Iterator iter = fsn.getFSDirectory()
-  .getINodeMap().getMapIterator();
+  FSDirectory dir = fsn.getFSDirectory();
+  Iterator iter = dir.getINodeMap()
+  .getMapIterator();
   final ArrayList refList = parent.getSaverContext()
   .getRefList();
   int i = 0;
@@ -545,6 +549,17 @@ public final class FSImageFormatPBINode {
   INodeDirectorySection.DirEntry.Builder b = INodeDirectorySection.
   DirEntry.newBuilder().setParent(n.getId());
   for (INode inode : children) {
+// Error if the child inode doesn't exist in inodeMap
+if (dir.getInode(inode.getId()) == null) {
+  FSImage.LOG.error(
+  "FSImageFormatPBINode#serializeINodeDirectorySection: " +
+  "Dangling child pointer found. Missing INode in " +
+  "inodeMap: id=" + inode.getId() +
+  "; path=" + inode.getFullPathName() +
+  "; parent=" + (inode.getParent() == null ? "null" :
+  inode.getParent().getFullPathName()));
+  ++numImageErrors;
+}
 if (!inode.isReference()) {
   b.addChildren(inode.getId());
 } else {
@@ -672,6 +687,15 @@ public final class FSImageFormatPBINode {
   .setId(n.getId())
   .setName(ByteString.copyFrom(n.getLocalNameBytes()));
 }
+
+/**
+ * Number of non-fatal errors detected while writing the
+ * INodeSection and INodeDirectorySection sections.
+ * @return the number of non-fatal errors detected.
+ */
+public long getNumImageErrors() {
+  return numImageErrors;
+}
   }
 
   private FSImageFormatPBINode() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ad5c3300/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
index 718f0ec..6a7b9db 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
+++ 

hadoop git commit: HDFS-13813. Exit NameNode if dangling child inode is detected when saving FsImage. Contributed by Siyao Meng.

2018-08-13 Thread weichiu
Repository: hadoop
Updated Branches:
  refs/heads/branch-3.0 eecfbaff3 -> 4b606eb9f


HDFS-13813. Exit NameNode if dangling child inode is detected when saving 
FsImage. Contributed by Siyao Meng.

(cherry picked from commit 23854443efa62aa70a1c30c32c3816750e5d7a5b)
(cherry picked from commit b38649c59a70b3112811443464b3b3180f4b9873)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/4b606eb9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/4b606eb9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/4b606eb9

Branch: refs/heads/branch-3.0
Commit: 4b606eb9fd5dde5629e791d3338886a70b5aa57c
Parents: eecfbaf
Author: Wei-Chiu Chuang 
Authored: Mon Aug 13 16:12:37 2018 -0700
Committer: Wei-Chiu Chuang 
Committed: Mon Aug 13 16:14:01 2018 -0700

--
 .../server/namenode/FSImageFormatPBINode.java   | 28 ++--
 .../server/namenode/FSImageFormatProtobuf.java  |  9 ---
 2 files changed, 32 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b606eb9/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
index 5e60038..a233d26 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
@@ -439,6 +439,8 @@ public final class FSImageFormatPBINode {
   }
 
   public final static class Saver {
+private long numImageErrors;
+
 private static long buildPermissionStatus(INodeAttributes n,
 final SaverContext.DeduplicationMap stringMap) {
   long userId = stringMap.getId(n.getUserName());
@@ -563,11 +565,13 @@ public final class FSImageFormatPBINode {
   this.summary = summary;
   this.context = parent.getContext();
   this.fsn = context.getSourceNamesystem();
+  this.numImageErrors = 0;
 }
 
 void serializeINodeDirectorySection(OutputStream out) throws IOException {
-  Iterator iter = fsn.getFSDirectory()
-  .getINodeMap().getMapIterator();
+  FSDirectory dir = fsn.getFSDirectory();
+  Iterator iter = dir.getINodeMap()
+  .getMapIterator();
   final ArrayList refList = parent.getSaverContext()
   .getRefList();
   int i = 0;
@@ -583,6 +587,17 @@ public final class FSImageFormatPBINode {
   INodeDirectorySection.DirEntry.Builder b = INodeDirectorySection.
   DirEntry.newBuilder().setParent(n.getId());
   for (INode inode : children) {
+// Error if the child inode doesn't exist in inodeMap
+if (dir.getInode(inode.getId()) == null) {
+  FSImage.LOG.error(
+  "FSImageFormatPBINode#serializeINodeDirectorySection: " +
+  "Dangling child pointer found. Missing INode in " +
+  "inodeMap: id=" + inode.getId() +
+  "; path=" + inode.getFullPathName() +
+  "; parent=" + (inode.getParent() == null ? "null" :
+  inode.getParent().getFullPathName()));
+  ++numImageErrors;
+}
 if (!inode.isReference()) {
   b.addChildren(inode.getId());
 } else {
@@ -711,6 +726,15 @@ public final class FSImageFormatPBINode {
   .setId(n.getId())
   .setName(ByteString.copyFrom(n.getLocalNameBytes()));
 }
+
+/**
+ * Number of non-fatal errors detected while writing the
+ * INodeSection and INodeDirectorySection sections.
+ * @return the number of non-fatal errors detected.
+ */
+public long getNumImageErrors() {
+  return numImageErrors;
+}
   }
 
   private FSImageFormatPBINode() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b606eb9/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
index 4ac20ad..9752733 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
+++ 

hadoop git commit: HDFS-13813. Exit NameNode if dangling child inode is detected when saving FsImage. Contributed by Siyao Meng.

2018-08-13 Thread weichiu
Repository: hadoop
Updated Branches:
  refs/heads/branch-3.1 b3f29e350 -> b38649c59


HDFS-13813. Exit NameNode if dangling child inode is detected when saving 
FsImage. Contributed by Siyao Meng.

(cherry picked from commit 23854443efa62aa70a1c30c32c3816750e5d7a5b)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b38649c5
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b38649c5
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b38649c5

Branch: refs/heads/branch-3.1
Commit: b38649c59a70b3112811443464b3b3180f4b9873
Parents: b3f29e3
Author: Wei-Chiu Chuang 
Authored: Mon Aug 13 16:12:37 2018 -0700
Committer: Wei-Chiu Chuang 
Committed: Mon Aug 13 16:13:36 2018 -0700

--
 .../server/namenode/FSImageFormatPBINode.java   | 28 ++--
 .../server/namenode/FSImageFormatProtobuf.java  |  9 ---
 2 files changed, 32 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b38649c5/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
index 5e60038..a233d26 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
@@ -439,6 +439,8 @@ public final class FSImageFormatPBINode {
   }
 
   public final static class Saver {
+private long numImageErrors;
+
 private static long buildPermissionStatus(INodeAttributes n,
 final SaverContext.DeduplicationMap stringMap) {
   long userId = stringMap.getId(n.getUserName());
@@ -563,11 +565,13 @@ public final class FSImageFormatPBINode {
   this.summary = summary;
   this.context = parent.getContext();
   this.fsn = context.getSourceNamesystem();
+  this.numImageErrors = 0;
 }
 
 void serializeINodeDirectorySection(OutputStream out) throws IOException {
-  Iterator iter = fsn.getFSDirectory()
-  .getINodeMap().getMapIterator();
+  FSDirectory dir = fsn.getFSDirectory();
+  Iterator iter = dir.getINodeMap()
+  .getMapIterator();
   final ArrayList refList = parent.getSaverContext()
   .getRefList();
   int i = 0;
@@ -583,6 +587,17 @@ public final class FSImageFormatPBINode {
   INodeDirectorySection.DirEntry.Builder b = INodeDirectorySection.
   DirEntry.newBuilder().setParent(n.getId());
   for (INode inode : children) {
+// Error if the child inode doesn't exist in inodeMap
+if (dir.getInode(inode.getId()) == null) {
+  FSImage.LOG.error(
+  "FSImageFormatPBINode#serializeINodeDirectorySection: " +
+  "Dangling child pointer found. Missing INode in " +
+  "inodeMap: id=" + inode.getId() +
+  "; path=" + inode.getFullPathName() +
+  "; parent=" + (inode.getParent() == null ? "null" :
+  inode.getParent().getFullPathName()));
+  ++numImageErrors;
+}
 if (!inode.isReference()) {
   b.addChildren(inode.getId());
 } else {
@@ -711,6 +726,15 @@ public final class FSImageFormatPBINode {
   .setId(n.getId())
   .setName(ByteString.copyFrom(n.getLocalNameBytes()));
 }
+
+/**
+ * Number of non-fatal errors detected while writing the
+ * INodeSection and INodeDirectorySection sections.
+ * @return the number of non-fatal errors detected.
+ */
+public long getNumImageErrors() {
+  return numImageErrors;
+}
   }
 
   private FSImageFormatPBINode() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b38649c5/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
index 4ac20ad..9752733 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
@@ -474,13 +474,15 @@ 

hadoop git commit: HDFS-13813. Exit NameNode if dangling child inode is detected when saving FsImage. Contributed by Siyao Meng.

2018-08-13 Thread weichiu
Repository: hadoop
Updated Branches:
  refs/heads/trunk 74411ce0c -> 23854443e


HDFS-13813. Exit NameNode if dangling child inode is detected when saving 
FsImage. Contributed by Siyao Meng.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/23854443
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/23854443
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/23854443

Branch: refs/heads/trunk
Commit: 23854443efa62aa70a1c30c32c3816750e5d7a5b
Parents: 74411ce
Author: Wei-Chiu Chuang 
Authored: Mon Aug 13 16:12:37 2018 -0700
Committer: Wei-Chiu Chuang 
Committed: Mon Aug 13 16:12:37 2018 -0700

--
 .../server/namenode/FSImageFormatPBINode.java   | 28 ++--
 .../server/namenode/FSImageFormatProtobuf.java  |  9 ---
 2 files changed, 32 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/23854443/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
index 5e60038..a233d26 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java
@@ -439,6 +439,8 @@ public final class FSImageFormatPBINode {
   }
 
   public final static class Saver {
+private long numImageErrors;
+
 private static long buildPermissionStatus(INodeAttributes n,
 final SaverContext.DeduplicationMap stringMap) {
   long userId = stringMap.getId(n.getUserName());
@@ -563,11 +565,13 @@ public final class FSImageFormatPBINode {
   this.summary = summary;
   this.context = parent.getContext();
   this.fsn = context.getSourceNamesystem();
+  this.numImageErrors = 0;
 }
 
 void serializeINodeDirectorySection(OutputStream out) throws IOException {
-  Iterator iter = fsn.getFSDirectory()
-  .getINodeMap().getMapIterator();
+  FSDirectory dir = fsn.getFSDirectory();
+  Iterator iter = dir.getINodeMap()
+  .getMapIterator();
   final ArrayList refList = parent.getSaverContext()
   .getRefList();
   int i = 0;
@@ -583,6 +587,17 @@ public final class FSImageFormatPBINode {
   INodeDirectorySection.DirEntry.Builder b = INodeDirectorySection.
   DirEntry.newBuilder().setParent(n.getId());
   for (INode inode : children) {
+// Error if the child inode doesn't exist in inodeMap
+if (dir.getInode(inode.getId()) == null) {
+  FSImage.LOG.error(
+  "FSImageFormatPBINode#serializeINodeDirectorySection: " +
+  "Dangling child pointer found. Missing INode in " +
+  "inodeMap: id=" + inode.getId() +
+  "; path=" + inode.getFullPathName() +
+  "; parent=" + (inode.getParent() == null ? "null" :
+  inode.getParent().getFullPathName()));
+  ++numImageErrors;
+}
 if (!inode.isReference()) {
   b.addChildren(inode.getId());
 } else {
@@ -711,6 +726,15 @@ public final class FSImageFormatPBINode {
   .setId(n.getId())
   .setName(ByteString.copyFrom(n.getLocalNameBytes()));
 }
+
+/**
+ * Number of non-fatal errors detected while writing the
+ * INodeSection and INodeDirectorySection sections.
+ * @return the number of non-fatal errors detected.
+ */
+public long getNumImageErrors() {
+  return numImageErrors;
+}
   }
 
   private FSImageFormatPBINode() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/23854443/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
--
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
index 4ac20ad..9752733 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatProtobuf.java
@@ -474,13 +474,15 @@ public final class FSImageFormatProtobuf {
   out.write(lengthBytes);
 }