HDFS-15816. Fix shouldAvoidStaleDataNodesForWrite returns when no stale node in cluster. Contributed by Yang Yun.

This commit is contained in:
He Xiaoqiao 2021-03-14 17:48:18 +08:00
parent fe633d4739
commit 970455c917
No known key found for this signature in database
GPG Key ID: A80CC124E9A0FA63
2 changed files with 13 additions and 1 deletions

View File

@ -1321,7 +1321,7 @@ public List<DatanodeDescriptor> getEnteringMaintenanceNodes() {
public boolean shouldAvoidStaleDataNodesForWrite() {
// If # stale exceeds maximum staleness ratio, disable stale
// datanode avoidance on the write path
return avoidStaleDataNodesForWrite &&
return avoidStaleDataNodesForWrite && numStaleNodes > 0 &&
(numStaleNodes <= heartbeatManager.getLiveDatanodeCount()
* ratioUseStaleDataNodesForWrite);
}

View File

@ -1664,4 +1664,16 @@ public void testChosenFailureForStorageType() {
assertNotEquals(0,
appender.countLinesWithMessage("NO_REQUIRED_STORAGE_TYPE"));
}
@Test
public void testReduceChooseTimesIfNOStaleNode() {
for(int i = 0; i < 6; i++) {
updateHeartbeatWithUsage(dataNodes[i],
2 * HdfsServerConstants.MIN_BLOCKS_FOR_WRITE * BLOCK_SIZE, 0L,
(HdfsServerConstants.MIN_BLOCKS_FOR_WRITE - 1) * BLOCK_SIZE,
0L, 0L, 0L, 0, 0);
}
assertFalse(dnManager.shouldAvoidStaleDataNodesForWrite());
resetHeartbeatForStorages();
}
}