From 05c08efa682ea4ebc80f43d9b15e41735d42c77d Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Thu, 3 May 2012 23:34:35 +0000 Subject: [PATCH] svn merge -c 1333679 from trunk for HDFS-3350. In INode, add final to compareTo(..), equals(..) and hashCode(), and remove synchronized from updatePermissionStatus(..). git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1333680 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 + .../hadoop/hdfs/server/namenode/INode.java | 55 +++++++------------ .../hdfs/server/namenode/INodeDirectory.java | 9 ++- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 4a13c954704..551f7787be1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -473,6 +473,9 @@ Release 2.0.0 - UNRELEASED HDFS-3359. DFSClient.close should close cached sockets. (todd) + HDFS-3350. In INode, add final to compareTo(..), equals(..) and hashCode(), + and remove synchronized from updatePermissionStatus(..). (szetszwo) + BREAKDOWN OF HDFS-1623 SUBTASKS HDFS-2179. Add fencing framework and mechanisms for NameNode HA. (todd) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java index cdad315f7a4..2bc049dbfa7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INode.java @@ -30,6 +30,8 @@ import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo; import org.apache.hadoop.util.StringUtils; +import com.google.common.primitives.SignedBytes; + /** * We keep an in-memory representation of the file/block hierarchy. * This is a base INode class containing common fields for file and @@ -143,8 +145,7 @@ abstract class INode implements Comparable, FSInodeInfo { protected PermissionStatus getPermissionStatus() { return new PermissionStatus(getUserName(),getGroupName(),getFsPermission()); } - private synchronized void updatePermissionStatus( - PermissionStatusFormat f, long n) { + private void updatePermissionStatus(PermissionStatusFormat f, long n) { permission = f.combine(n, permission); } /** Get user name */ @@ -400,48 +401,30 @@ abstract class INode implements Comparable, FSInodeInfo { } } - // - // Comparable interface - // - public int compareTo(byte[] o) { - return compareBytes(name, o); + private static final byte[] EMPTY_BYTES = {}; + + @Override + public final int compareTo(byte[] bytes) { + final byte[] left = name == null? EMPTY_BYTES: name; + final byte[] right = bytes == null? EMPTY_BYTES: bytes; + return SignedBytes.lexicographicalComparator().compare(left, right); } - public boolean equals(Object o) { - if (!(o instanceof INode)) { + @Override + public final boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null || !(that instanceof INode)) { return false; } - return Arrays.equals(this.name, ((INode)o).name); + return Arrays.equals(this.name, ((INode)that).name); } - public int hashCode() { + @Override + public final int hashCode() { return Arrays.hashCode(this.name); } - - // - // static methods - // - /** - * Compare two byte arrays. - * - * @return a negative integer, zero, or a positive integer - * as defined by {@link #compareTo(byte[])}. - */ - static int compareBytes(byte[] a1, byte[] a2) { - if (a1==a2) - return 0; - int len1 = (a1==null ? 0 : a1.length); - int len2 = (a2==null ? 0 : a2.length); - int n = Math.min(len1, len2); - byte b1, b2; - for (int i=0; i