2121import java .util .Map ;
2222import java .util .concurrent .atomic .AtomicLong ;
2323
24+ import org .apache .hadoop .hdfs .protocol .Block ;
2425import org .apache .hadoop .hdfs .server .namenode .NameNode ;
2526import org .apache .hadoop .hdfs .util .LightWeightHashSet ;
2627import org .slf4j .Logger ;
3738class ExcessRedundancyMap {
3839 public static final Logger blockLog = NameNode .blockStateChangeLog ;
3940
40- private final Map <String , LightWeightHashSet <ExcessBlockInfo >> map = new HashMap <>();
41+ private final Map <String , LightWeightHashSet <Block >> map = new HashMap <>();
4142 private final AtomicLong size = new AtomicLong (0L );
4243
4344 /**
@@ -52,7 +53,7 @@ long size() {
5253 */
5354 @ VisibleForTesting
5455 synchronized int getSize4Testing (String dnUuid ) {
55- final LightWeightHashSet <ExcessBlockInfo > set = map .get (dnUuid );
56+ final LightWeightHashSet <Block > set = map .get (dnUuid );
5657 return set == null ? 0 : set .size ();
5758 }
5859
@@ -66,7 +67,7 @@ synchronized void clear() {
6667 * datanode and the given block?
6768 */
6869 synchronized boolean contains (DatanodeDescriptor dn , BlockInfo blk ) {
69- final LightWeightHashSet <ExcessBlockInfo > set = map .get (dn .getDatanodeUuid ());
70+ final LightWeightHashSet <Block > set = map .get (dn .getDatanodeUuid ());
7071 return set != null && set .contains (blk );
7172 }
7273
@@ -77,7 +78,7 @@ synchronized boolean contains(DatanodeDescriptor dn, BlockInfo blk) {
7778 * @return true if the block is added.
7879 */
7980 synchronized boolean add (DatanodeDescriptor dn , BlockInfo blk ) {
80- LightWeightHashSet <ExcessBlockInfo > set = map .get (dn .getDatanodeUuid ());
81+ LightWeightHashSet <Block > set = map .get (dn .getDatanodeUuid ());
8182 if (set == null ) {
8283 set = new LightWeightHashSet <>();
8384 map .put (dn .getDatanodeUuid (), set );
@@ -97,11 +98,10 @@ synchronized boolean add(DatanodeDescriptor dn, BlockInfo blk) {
9798 * @return true if the block is removed.
9899 */
99100 synchronized boolean remove (DatanodeDescriptor dn , BlockInfo blk ) {
100- final LightWeightHashSet <ExcessBlockInfo > set = map .get (dn .getDatanodeUuid ());
101+ final LightWeightHashSet <Block > set = map .get (dn .getDatanodeUuid ());
101102 if (set == null ) {
102103 return false ;
103104 }
104-
105105 final boolean removed = set .remove (blk );
106106 if (removed ) {
107107 size .decrementAndGet ();
@@ -114,19 +114,20 @@ synchronized boolean remove(DatanodeDescriptor dn, BlockInfo blk) {
114114 return removed ;
115115 }
116116
117- synchronized Map <String , LightWeightHashSet <ExcessBlockInfo >> getExcessRedundancyMap () {
117+ synchronized Map <String , LightWeightHashSet <Block >> getExcessRedundancyMap () {
118118 return map ;
119119 }
120120
121121 /**
122122 * An object that contains information about a block that is being excess redundancy.
123123 * It records the timestamp when added excess redundancy map of this block.
124124 */
125- static class ExcessBlockInfo implements Comparable < ExcessBlockInfo > {
125+ static class ExcessBlockInfo extends Block {
126126 private long timeStamp ;
127- private BlockInfo blockInfo ;
127+ private final BlockInfo blockInfo ;
128128
129129 ExcessBlockInfo (BlockInfo blockInfo ) {
130+ super (blockInfo .getBlockId (), blockInfo .getNumBytes (), blockInfo .getGenerationStamp ());
130131 this .timeStamp = monotonicNow ();
131132 this .blockInfo = blockInfo ;
132133 }
@@ -145,29 +146,12 @@ void setTimeStamp() {
145146
146147 @ Override
147148 public int hashCode () {
148- return blockInfo .hashCode ();
149+ return super .hashCode ();
149150 }
150151
151152 @ Override
152153 public boolean equals (Object obj ) {
153- if (this == obj ) {
154- return true ;
155- }
156-
157- if (obj instanceof ExcessBlockInfo ) {
158- ExcessBlockInfo other = (ExcessBlockInfo ) obj ;
159- return this .blockInfo .equals (other .blockInfo );
160- }
161-
162- if (obj instanceof BlockInfo ) {
163- return this .blockInfo .equals (obj );
164- }
165- return false ;
166- }
167-
168- @ Override
169- public int compareTo (ExcessBlockInfo o ) {
170- return Long .compare (this .timeStamp , o .timeStamp );
154+ return super .equals (obj );
171155 }
172156 }
173157}
0 commit comments