From a68b5b31cf846c0fc94c430bafd07a9bca369234 Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Tue, 25 Jul 2017 11:03:09 -0500 Subject: [PATCH] HDFS-12171. Reduce IIP object allocations for inode lookup. Contributed by Daryn Sharp. --- .../namenode/EncryptionZoneManager.java | 5 ++--- .../server/namenode/FSDirErasureCodingOp.java | 5 ++--- .../hdfs/server/namenode/INodesInPath.java | 19 ++----------------- .../namenode/TestSnapshotPathINodes.java | 5 ++--- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java index 6dff62b97ee..96e189b91b5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EncryptionZoneManager.java @@ -209,9 +209,8 @@ public class EncryptionZoneManager { if (!hasCreatedEncryptionZone()) { return null; } - List inodes = iip.getReadOnlyINodes(); - for (int i = inodes.size() - 1; i >= 0; i--) { - final INode inode = inodes.get(i); + for (int i = iip.length() - 1; i >= 0; i--) { + final INode inode = iip.getINode(i); if (inode != null) { final EncryptionZoneInt ezi = encryptionZones.get(inode.getId()); if (ezi != null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java index 681f217d408..486503cbf7f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirErasureCodingOp.java @@ -355,9 +355,8 @@ final class FSDirErasureCodingOp { Preconditions.checkNotNull(iip, "INodes cannot be null"); fsd.readLock(); try { - List inodes = iip.getReadOnlyINodes(); - for (int i = inodes.size() - 1; i >= 0; i--) { - final INode inode = inodes.get(i); + for (int i = iip.length() - 1; i >= 0; i--) { + final INode inode = iip.getINode(i); if (inode == null) { continue; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java index abc8b6357f0..8235bf07d52 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodesInPath.java @@ -18,9 +18,6 @@ package org.apache.hadoop.hdfs.server.namenode; import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.NoSuchElementException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -336,17 +333,9 @@ public class INodesInPath { * otherwise, i < 0, return the (length + i)-th inode. */ public INode getINode(int i) { - if (inodes == null || inodes.length == 0) { - throw new NoSuchElementException("inodes is null or empty"); - } - int index = i >= 0 ? i : inodes.length + i; - if (index < inodes.length && index >= 0) { - return inodes[index]; - } else { - throw new NoSuchElementException("inodes.length == " + inodes.length); - } + return inodes[(i < 0) ? inodes.length + i : i]; } - + /** @return the last inode. */ public INode getLastINode() { return getINode(-1); @@ -384,10 +373,6 @@ public class INodesInPath { return inodes.length; } - public List getReadOnlyINodes() { - return Collections.unmodifiableList(Arrays.asList(inodes)); - } - public INode[] getINodesArray() { INode[] retArr = new INode[inodes.length]; System.arraycopy(inodes, 0, retArr, 0, inodes.length); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSnapshotPathINodes.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSnapshotPathINodes.java index d1d915e2ea4..b62a4180d43 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSnapshotPathINodes.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSnapshotPathINodes.java @@ -310,9 +310,8 @@ public class TestSnapshotPathINodes { } private int getNumNonNull(INodesInPath iip) { - List inodes = iip.getReadOnlyINodes(); - for (int i = inodes.size() - 1; i >= 0; i--) { - if (inodes.get(i) != null) { + for (int i = iip.length() - 1; i >= 0; i--) { + if (iip.getINode(i) != null) { return i+1; } }