Repository: hadoop Updated Branches: refs/heads/branch-2 22f237c5d -> 9fe5dd098
HDFS-12143. Improve performance of getting and removing inode features. Contributed by Daryn Sharp. (cherry picked from commit 1a79dcfc457969d6a6c08ffffe4152fd7638e48a) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/9fe5dd09 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/9fe5dd09 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/9fe5dd09 Branch: refs/heads/branch-2 Commit: 9fe5dd098d0c53b854ae10dc56f7e75d2926754a Parents: 22f237c Author: Kihwal Lee <kih...@apache.org> Authored: Tue Jul 25 10:30:27 2017 -0500 Committer: Kihwal Lee <kih...@apache.org> Committed: Tue Jul 25 10:30:27 2017 -0500 ---------------------------------------------------------------------- .../namenode/INodeWithAdditionalFields.java | 24 ++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/9fe5dd09/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java index 8ff15a8..bb7d98a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeWithAdditionalFields.java @@ -283,12 +283,14 @@ public abstract class INodeWithAdditionalFields extends INode protected void removeFeature(Feature f) { int size = features.length; - Preconditions.checkState(size > 0, "Feature " - + f.getClass().getSimpleName() + " not found."); + if (size == 0) { + throwFeatureNotFoundException(f); + } if (size == 1) { - Preconditions.checkState(features[0] == f, "Feature " - + f.getClass().getSimpleName() + " not found."); + if (features[0] != f) { + throwFeatureNotFoundException(f); + } features = EMPTY_FEATURE; return; } @@ -307,14 +309,22 @@ public abstract class INodeWithAdditionalFields extends INode } } - Preconditions.checkState(!overflow && j == size - 1, "Feature " - + f.getClass().getSimpleName() + " not found."); + if (overflow || j != size - 1) { + throwFeatureNotFoundException(f); + } features = arr; } + private void throwFeatureNotFoundException(Feature f) { + throw new IllegalStateException( + "Feature " + f.getClass().getSimpleName() + " not found."); + } + protected <T extends Feature> T getFeature(Class<? extends Feature> clazz) { Preconditions.checkArgument(clazz != null); - for (Feature f : features) { + final int size = features.length; + for (int i=0; i < size; i++) { + Feature f = features[i]; if (clazz.isAssignableFrom(f.getClass())) { @SuppressWarnings("unchecked") T ret = (T) f; --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org