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 bc455e07c00..6825a5c4857 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 @@ -269,7 +269,7 @@ public final class FSImageFormatPBINode { + "name before upgrading to this release."); } // NOTE: This does not update space counts for parents - if (!parent.addChild(child)) { + if (!parent.addChildAtLoading(child)) { return; } dir.cacheName(child); @@ -551,6 +551,8 @@ public final class FSImageFormatPBINode { ++numImageErrors; } if (!inode.isReference()) { + // Serialization must ensure that children are in order, related + // to HDFS-13693 b.addChildren(inode.getId()); } else { refList.add(inode.asReference()); 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 433abcb21b2..28eb3d2af4c 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 @@ -572,6 +572,22 @@ public class INodeDirectory extends INodeWithAdditionalFields return true; } + /** + * During image loading, the search is unnecessary since the insert position + * should always be at the end of the map given the sequence they are + * serialized on disk. + */ + public boolean addChildAtLoading(INode node) { + int pos; + if (!node.isReference()) { + pos = (children == null) ? (-1) : (-children.size() - 1); + addChild(node, pos); + return true; + } else { + return addChild(node); + } + } + /** * Add the node to the children list at the given insertion point. * The basic add method which actually calls children.add(..).