Skip to content

Commit 77c1342

Browse files
committed
HDFS-17218. Modify patch based on comments
1 parent cafe3c6 commit 77c1342

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,7 +3104,7 @@ void processTimedOutExcessBlocks() {
31043104
Map.Entry<String, LightWeightHashSet<ExcessBlockInfo>> entry = iter.next();
31053105
String datanodeUuid = entry.getKey();
31063106
LightWeightHashSet<ExcessBlockInfo> blocks = entry.getValue();
3107-
List<ExcessRedundancyMap.ExcessBlockInfo> sortedBlocks = new ArrayList<>(blocks);
3107+
List<ExcessBlockInfo> sortedBlocks = new ArrayList<>(blocks);
31083108
// Sort blocks by timestamp in descending order.
31093109
Collections.sort(sortedBlocks);
31103110

@@ -3130,18 +3130,16 @@ void processTimedOutExcessBlocks() {
31303130
while (iterator.hasNext()) {
31313131
DatanodeStorageInfo datanodeStorageInfo = iterator.next();
31323132
DatanodeDescriptor datanodeDescriptor = datanodeStorageInfo.getDatanodeDescriptor();
3133-
if (datanodeDescriptor.getDatanodeUuid().equals(datanodeUuid)) {
3134-
if (datanodeStorageInfo.getState().equals(State.NORMAL)) {
3135-
final Block block = getBlockOnStorage(blockInfo,
3136-
datanodeStorageInfo);
3137-
if (!containsInvalidateBlock(datanodeDescriptor, block)) {
3138-
addToInvalidates(block, datanodeDescriptor);
3139-
LOG.debug("Excess block timeout ({}, {}) is added to invalidated.",
3140-
block, datanodeDescriptor);
3141-
}
3142-
excessBlockInfo.setTimeStamp();
3143-
break;
3133+
if (datanodeDescriptor.getDatanodeUuid().equals(datanodeUuid) &&
3134+
datanodeStorageInfo.getState().equals(State.NORMAL)) {
3135+
final Block block = getBlockOnStorage(blockInfo, datanodeStorageInfo);
3136+
if (!containsInvalidateBlock(datanodeDescriptor, block)) {
3137+
addToInvalidates(block, datanodeDescriptor);
3138+
LOG.debug("Excess block timeout ({}, {}) is added to invalidated.",
3139+
block, datanodeDescriptor);
31443140
}
3141+
excessBlockInfo.setTimeStamp();
3142+
break;
31453143
}
31463144
}
31473145
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/ExcessRedundancyMap.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ synchronized void clear() {
6767
*/
6868
synchronized boolean contains(DatanodeDescriptor dn, BlockInfo blk) {
6969
final LightWeightHashSet<ExcessBlockInfo> set = map.get(dn.getDatanodeUuid());
70-
return set != null && set.contains(new ExcessBlockInfo(blk));
70+
return set != null && set.contains(blk);
7171
}
7272

7373
/**
@@ -102,7 +102,7 @@ synchronized boolean remove(DatanodeDescriptor dn, BlockInfo blk) {
102102
return false;
103103
}
104104

105-
final boolean removed = set.remove(new ExcessBlockInfo(blk));
105+
final boolean removed = set.remove(blk);
106106
if (removed) {
107107
size.decrementAndGet();
108108
blockLog.debug("BLOCK* ExcessRedundancyMap.remove({}, {})", dn, blk);
@@ -153,11 +153,16 @@ public boolean equals(Object obj) {
153153
if (this == obj) {
154154
return true;
155155
}
156-
if (!(obj instanceof ExcessBlockInfo)) {
157-
return false;
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);
158164
}
159-
ExcessBlockInfo other = (ExcessBlockInfo) obj;
160-
return (this.blockInfo.equals(other.blockInfo));
165+
return false;
161166
}
162167

163168
@Override

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/blockmanagement/TestBlockManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ public void delayDeleteReplica() {
22712271
assertEquals(0, blockManager.getPendingDeletionBlocksCount());
22722272
assertNotNull(excessDn);
22732273

2274-
// Name node will ask datanode to delete replicas in heartbeat response.
2274+
// NameNode will ask datanode to delete replicas in heartbeat response.
22752275
cluster.triggerHeartbeats();
22762276

22772277
// Wait for the datanode to process any block deletions

0 commit comments

Comments
 (0)