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 cd...@apache.org on 2008/05/19 23:20:24 UTC

svn commit: r657985 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/mapred/ReduceTask.java

Author: cdouglas
Date: Mon May 19 14:20:24 2008
New Revision: 657985

URL: http://svn.apache.org/viewvc?rev=657985&view=rev
Log:
HADOOP-3398. Minor improvement to a utility function in that participates in
backoff calculation.


Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/mapred/ReduceTask.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=657985&r1=657984&r2=657985&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon May 19 14:20:24 2008
@@ -146,6 +146,9 @@
     HADOOP-3377. Remove TaskRunner::replaceAll and replace with equivalent
     String::replace. (Brice Arnould via cdouglas)
 
+    HADOOP-3398. Minor improvement to a utility function in that participates
+    in backoff calculation. (cdouglas)
+
   OPTIMIZATIONS
 
     HADOOP-3274. The default constructor of BytesWritable creates empty 

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/mapred/ReduceTask.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/mapred/ReduceTask.java?rev=657985&r1=657984&r2=657985&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/mapred/ReduceTask.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/mapred/ReduceTask.java Mon May 19 14:20:24 2008
@@ -1731,16 +1731,18 @@
 
   }
 
+  /**
+   * Return the exponent of the power of two closest to the given
+   * positive value, or zero if value leq 0.
+   * This follows the observation that the msb of a given value is
+   * also the closest power of two, unless the bit following it is
+   * set.
+   */
   private static int getClosestPowerOf2(int value) {
-    int power = 0;
-    int approx = 1;
-    while (approx < value) {
-      ++power;
-      approx = (approx << 1);
-    }
-    if ((value - (approx >> 1)) < (approx - value)) {
-      --power;
-    }
-    return power;
+    if (value <= 0)
+      throw new IllegalArgumentException("Undefined for " + value);
+    final int hob = Integer.highestOneBit(value);
+    return Integer.numberOfTrailingZeros(hob) +
+      (((hob >>> 1) & value) == 0 ? 0 : 1);
   }
 }