Skip to content

Commit 7025724

Browse files
ayushtknjojochuang
authored andcommitted
HDFS-13693. Remove unnecessary search in INodeDirectory.addChild during image loading. Contributed by Lisheng Sun.
(cherry picked from commit 377f95b)
1 parent 732a68c commit 7025724

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormatPBINode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private void addToParent(INodeDirectory parent, INode child) {
269269
+ "name before upgrading to this release.");
270270
}
271271
// NOTE: This does not update space counts for parents
272-
if (!parent.addChild(child)) {
272+
if (!parent.addChildAtLoading(child)) {
273273
return;
274274
}
275275
dir.cacheName(child);
@@ -551,6 +551,8 @@ void serializeINodeDirectorySection(OutputStream out) throws IOException {
551551
++numImageErrors;
552552
}
553553
if (!inode.isReference()) {
554+
// Serialization must ensure that children are in order, related
555+
// to HDFS-13693
554556
b.addChildren(inode.getId());
555557
} else {
556558
refList.add(inode.asReference());

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeDirectory.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,22 @@ public boolean addChild(INode node) {
572572
return true;
573573
}
574574

575+
/**
576+
* During image loading, the search is unnecessary since the insert position
577+
* should always be at the end of the map given the sequence they are
578+
* serialized on disk.
579+
*/
580+
public boolean addChildAtLoading(INode node) {
581+
int pos;
582+
if (!node.isReference()) {
583+
pos = (children == null) ? (-1) : (-children.size() - 1);
584+
addChild(node, pos);
585+
return true;
586+
} else {
587+
return addChild(node);
588+
}
589+
}
590+
575591
/**
576592
* Add the node to the children list at the given insertion point.
577593
* The basic add method which actually calls children.add(..).

0 commit comments

Comments
 (0)