Author: szetszwo Date: Mon Jul 1 01:28:22 2013 New Revision: 1498202 URL: http://svn.apache.org/r1498202 Log: HDFS-4797. BlockScanInfo does not override equals(..) and hashCode() consistently.
Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1498202&r1=1498201&r2=1498202&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Mon Jul 1 01:28:22 2013 @@ -251,6 +251,9 @@ Release 2.2.0 - UNRELEASED BUG FIXES + HDFS-4797. BlockScanInfo does not override equals(..) and hashCode() + consistently. (szetszwo) + Release 2.1.1-beta - UNRELEASED INCOMPATIBLE CHANGES Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java?rev=1498202&r1=1498201&r2=1498202&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java (original) +++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceScanner.java Mon Jul 1 01:28:22 2013 @@ -24,6 +24,7 @@ import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -80,7 +81,7 @@ class BlockPoolSliceScanner { private final FsDatasetSpi<? extends FsVolumeSpi> dataset; private final SortedSet<BlockScanInfo> blockInfoSet - = new TreeSet<BlockScanInfo>(); + = new TreeSet<BlockScanInfo>(BlockScanInfo.LAST_SCAN_TIME_COMPARATOR); private final Map<Block, BlockScanInfo> blockMap = new HashMap<Block, BlockScanInfo>(); @@ -107,8 +108,20 @@ class BlockPoolSliceScanner { NONE, } - static class BlockScanInfo implements Comparable<BlockScanInfo> { - Block block; + static class BlockScanInfo { + /** Compare the info by the last scan time. */ + static final Comparator<BlockScanInfo> LAST_SCAN_TIME_COMPARATOR + = new Comparator<BlockPoolSliceScanner.BlockScanInfo>() { + + @Override + public int compare(BlockScanInfo left, BlockScanInfo right) { + final long l = left.lastScanTime; + final long r = right.lastScanTime; + return l < r? -1: l > r? 1: 0; + } + }; + + final Block block; long lastScanTime = 0; ScanType lastScanType = ScanType.NONE; boolean lastScanOk = true; @@ -123,22 +136,18 @@ class BlockPoolSliceScanner { } @Override - public boolean equals(Object other) { - return other instanceof BlockScanInfo && - compareTo((BlockScanInfo)other) == 0; + public boolean equals(Object that) { + if (this == that) { + return true; + } else if (that == null || !(that instanceof BlockScanInfo)) { + return false; + } + return block.equals(((BlockScanInfo)that).block); } long getLastScanTime() { return (lastScanType == ScanType.NONE) ? 0 : lastScanTime; } - - @Override - public int compareTo(BlockScanInfo other) { - long t1 = lastScanTime; - long t2 = other.lastScanTime; - return ( t1 < t2 ) ? -1 : - (( t1 > t2 ) ? 1 : block.compareTo(other.block)); - } } BlockPoolSliceScanner(String bpid, DataNode datanode,