From 8ce5015e94bd973c9e888342117267f14059944f Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Tue, 23 Jul 2019 08:37:55 +0530 Subject: [PATCH] HDFS-13693. Remove unnecessary search in INodeDirectory.addChild during image loading. Contributed by Lisheng Sun. (cherry picked from commit 377f95bbe8d2d171b5d7b0bfa7559e67ca4aae46) (cherry picked from commit e3f54a7babf942efbe879aabef65a5b6df57fb65) --- .../server/namenode/FSImageFormatPBINode.java | 4 +++- .../hdfs/server/namenode/INodeDirectory.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 3193c4fc3bb..5facc404db8 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 @@ -268,7 +268,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); @@ -550,6 +550,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 8fa9bcf2426..e71cb0a0678 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(..).