You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2013/08/06 20:28:06 UTC
svn commit: r1511065 - in
/hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common:
CHANGES.txt src/main/java/org/apache/hadoop/ipc/ClientId.java
src/main/java/org/apache/hadoop/ipc/RetryCache.java
Author: jing9
Date: Tue Aug 6 18:28:06 2013
New Revision: 1511065
URL: http://svn.apache.org/r1511065
Log:
HADOOP-9821. Merge change r1511063 from branch-2.
Modified:
hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientId.java
hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetryCache.java
Modified: hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1511065&r1=1511064&r2=1511065&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/CHANGES.txt Tue Aug 6 18:28:06 2013
@@ -35,6 +35,9 @@ Release 2.1.0-beta - 2013-08-06
HADOOP-9803. Add a generic type parameter to RetryInvocationHandler.
(szetszwo)
+ HADOOP-9821. ClientId should have getMsb/getLsb methods.
+ (Tsuyoshi OZAWA via jing9)
+
OPTIMIZATIONS
BUG FIXES
Modified: hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientId.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientId.java?rev=1511065&r1=1511064&r2=1511065&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientId.java (original)
+++ hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientId.java Tue Aug 6 18:28:06 2013
@@ -33,6 +33,7 @@ public class ClientId {
/** The byte array of a UUID should be 16 */
public static final int BYTE_LENGTH = 16;
+ private static final int shiftWidth = 8;
/**
* Return clientId as byte[]
@@ -53,15 +54,25 @@ public class ClientId {
}
// otherwise should be 16 bytes
Preconditions.checkArgument(clientId.length == BYTE_LENGTH);
+ long msb = getMsb(clientId);
+ long lsb = getLsb(clientId);
+ return (new UUID(msb, lsb)).toString();
+ }
+
+ public static long getMsb(byte[] clientId) {
long msb = 0;
- long lsb = 0;
- for (int i = 0; i < 8; i++) {
- msb = (msb << 8) | (clientId[i] & 0xff);
+ for (int i = 0; i < BYTE_LENGTH/2; i++) {
+ msb = (msb << shiftWidth) | (clientId[i] & 0xff);
}
- for (int i = 8; i < 16; i++) {
- lsb = (lsb << 8) | (clientId[i] & 0xff);
+ return msb;
+ }
+
+ public static long getLsb(byte[] clientId) {
+ long lsb = 0;
+ for (int i = BYTE_LENGTH/2; i < BYTE_LENGTH; i++) {
+ lsb = (lsb << shiftWidth) | (clientId[i] & 0xff);
}
- return (new UUID(msb, lsb)).toString();
+ return lsb;
}
/** Convert from clientId string byte[] representation of clientId */
Modified: hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetryCache.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetryCache.java?rev=1511065&r1=1511064&r2=1511065&view=diff
==============================================================================
--- hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetryCache.java (original)
+++ hadoop/common/branches/branch-2.1-beta/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RetryCache.java Tue Aug 6 18:28:06 2013
@@ -70,16 +70,8 @@ public class RetryCache {
"Invalid clientId - length is " + clientId.length
+ " expected length " + ClientId.BYTE_LENGTH);
// Convert UUID bytes to two longs
- long tmp = 0;
- for (int i=0; i<8; i++) {
- tmp = (tmp << 8) | (clientId[i] & 0xff);
- }
- clientIdMsb = tmp;
- tmp = 0;
- for (int i=8; i<16; i++) {
- tmp = (tmp << 8) | (clientId[i] & 0xff);
- }
- clientIdLsb = tmp;
+ clientIdMsb = ClientId.getMsb(clientId);
+ clientIdLsb = ClientId.getLsb(clientId);
this.callId = callId;
this.expirationTime = expirationTime;
}