Browse Source

MAPREDUCE-4272. SortedRanges.Range#compareTo is not spec compliant. (Yu Gao via llu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.0@1425183 13f79535-47bb-0310-9956-ffa450edef68
Luke Lu 12 years ago
parent
commit
68b8bf68a2
2 changed files with 9 additions and 5 deletions
  1. 3 0
      CHANGES.txt
  2. 6 5
      src/mapred/org/apache/hadoop/mapred/SortedRanges.java

+ 3 - 0
CHANGES.txt

@@ -8,6 +8,9 @@ Release 1.0.5 - unreleased
 
   BUG FIXES
 
+    MAPREDUCE-4272. SortedRanges.Range#compareTo is not spec compliant.
+    (Yu Gao via llu)
+
     HADOOP-9051. Fix ant clean/test with circular symlinks in build dir. (llu)
 
     MAPREDUCE-4396. Port support private distributed cache to

+ 6 - 5
src/mapred/org/apache/hadoop/mapred/SortedRanges.java

@@ -271,7 +271,7 @@ class SortedRanges implements Writable{
     }
     
     public boolean equals(Object o) {
-      if(o!=null && o instanceof Range) {
+      if (o instanceof Range) {
         Range range = (Range)o;
         return startIndex==range.startIndex &&
         length==range.length;
@@ -285,10 +285,11 @@ class SortedRanges implements Writable{
     }
     
     public int compareTo(Range o) {
-      if(this.equals(o)) {
-        return 0;
-      }
-      return (this.startIndex > o.startIndex) ? 1:-1;
+      // Ensure sgn(x.compareTo(y) == -sgn(y.compareTo(x))
+      return this.startIndex < o.startIndex ? -1 :
+          (this.startIndex > o.startIndex ? 1 :
+          (this.length < o.length ? -1 :
+          (this.length > o.length ? 1 : 0)));
     }
 
     public void readFields(DataInput in) throws IOException {