svn merge -c 1498202 from trunk for HDFS-4797. BlockScanInfo does not override equals(..) and hashCode() consistently.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1498203 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5808ba30dd
commit
797a30b5b7
|
@ -26,6 +26,9 @@ Release 2.2.0 - UNRELEASED
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
|
HDFS-4797. BlockScanInfo does not override equals(..) and hashCode()
|
||||||
|
consistently. (szetszwo)
|
||||||
|
|
||||||
Release 2.1.1-beta - UNRELEASED
|
Release 2.1.1-beta - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -80,7 +81,7 @@ class BlockPoolSliceScanner {
|
||||||
private final FsDatasetSpi<? extends FsVolumeSpi> dataset;
|
private final FsDatasetSpi<? extends FsVolumeSpi> dataset;
|
||||||
|
|
||||||
private final SortedSet<BlockScanInfo> blockInfoSet
|
private final SortedSet<BlockScanInfo> blockInfoSet
|
||||||
= new TreeSet<BlockScanInfo>();
|
= new TreeSet<BlockScanInfo>(BlockScanInfo.LAST_SCAN_TIME_COMPARATOR);
|
||||||
private final Map<Block, BlockScanInfo> blockMap
|
private final Map<Block, BlockScanInfo> blockMap
|
||||||
= new HashMap<Block, BlockScanInfo>();
|
= new HashMap<Block, BlockScanInfo>();
|
||||||
|
|
||||||
|
@ -107,8 +108,20 @@ class BlockPoolSliceScanner {
|
||||||
NONE,
|
NONE,
|
||||||
}
|
}
|
||||||
|
|
||||||
static class BlockScanInfo implements Comparable<BlockScanInfo> {
|
static class BlockScanInfo {
|
||||||
Block block;
|
/** 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;
|
long lastScanTime = 0;
|
||||||
ScanType lastScanType = ScanType.NONE;
|
ScanType lastScanType = ScanType.NONE;
|
||||||
boolean lastScanOk = true;
|
boolean lastScanOk = true;
|
||||||
|
@ -123,22 +136,18 @@ class BlockPoolSliceScanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object that) {
|
||||||
return other instanceof BlockScanInfo &&
|
if (this == that) {
|
||||||
compareTo((BlockScanInfo)other) == 0;
|
return true;
|
||||||
|
} else if (that == null || !(that instanceof BlockScanInfo)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return block.equals(((BlockScanInfo)that).block);
|
||||||
}
|
}
|
||||||
|
|
||||||
long getLastScanTime() {
|
long getLastScanTime() {
|
||||||
return (lastScanType == ScanType.NONE) ? 0 : lastScanTime;
|
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,
|
BlockPoolSliceScanner(String bpid, DataNode datanode,
|
||||||
|
|
Loading…
Reference in New Issue