Skip to content

Commit 7c4313a

Browse files
committed
MAPREDUCE-4272. SortedRanges.Range#compareTo was not spec compliant. (Yu Gao via llu)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1425180 13f79535-47bb-0310-9956-ffa450edef68
1 parent 915d030 commit 7c4313a

File tree

2 files changed

+9
-5
lines changed
  • hadoop-mapreduce-project

2 files changed

+9
-5
lines changed

hadoop-mapreduce-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Trunk (Unreleased)
8181

8282
BUG FIXES
8383

84+
MAPREDUCE-4272. SortedRanges.Range#compareTo is not spec compliant.
85+
(Yu Gao via llu)
86+
8487
MAPREDUCE-4356. [Rumen] Provide access to the method
8588
ParsedTask.obtainTaskAttempts(). (ravigummadi)
8689

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/SortedRanges.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ boolean isEmpty() {
271271
}
272272

273273
public boolean equals(Object o) {
274-
if(o!=null && o instanceof Range) {
274+
if (o instanceof Range) {
275275
Range range = (Range)o;
276276
return startIndex==range.startIndex &&
277277
length==range.length;
@@ -285,10 +285,11 @@ public int hashCode() {
285285
}
286286

287287
public int compareTo(Range o) {
288-
if(this.equals(o)) {
289-
return 0;
290-
}
291-
return (this.startIndex > o.startIndex) ? 1:-1;
288+
// Ensure sgn(x.compareTo(y) == -sgn(y.compareTo(x))
289+
return this.startIndex < o.startIndex ? -1 :
290+
(this.startIndex > o.startIndex ? 1 :
291+
(this.length < o.length ? -1 :
292+
(this.length > o.length ? 1 : 0)));
292293
}
293294

294295
public void readFields(DataInput in) throws IOException {

0 commit comments

Comments
 (0)