HDFS-14465. When the Block expected replications is larger than the number of DataNodes, entering maintenance will never exit. Contributed by Yicong Cai.

(cherry picked from commit 7db922c6474cb29e0e9bad320fcda4769366340a)
(cherry picked from commit 0eb42e1e05b780dab718bb3adfdd55f527dd5545)
(cherry picked from commit b3e0430c3bee30a52ec08786982522bfcf0bb911)
This commit is contained in:
Wei-Chiu Chuang 2019-06-17 15:16:41 -07:00
parent 2b9c4fccf4
commit fae98959ad
2 changed files with 10 additions and 2 deletions

View File

@ -344,7 +344,9 @@ private void setInMaintenance(DatanodeDescriptor dn) {
* @return true if sufficient, else false.
*/
private boolean isSufficient(BlockInfo block, BlockCollection bc,
NumberReplicas numberReplicas, boolean isDecommission) {
NumberReplicas numberReplicas,
boolean isDecommission,
boolean isMaintenance) {
if (blockManager.hasEnoughEffectiveReplicas(block, numberReplicas, 0)) {
// Block has enough replica, skip
LOG.trace("Block {} does not need replication.", block);
@ -378,6 +380,10 @@ private boolean isSufficient(BlockInfo block, BlockCollection bc,
}
}
}
if (isMaintenance
&& numLive >= blockManager.getMinReplicationToBeInMaintenance()) {
return true;
}
return false;
}
@ -705,6 +711,7 @@ private void processBlocksInternal(
// Schedule low redundancy blocks for reconstruction
// if not already pending.
boolean isDecommission = datanode.isDecommissionInProgress();
boolean isMaintenance = datanode.isEnteringMaintenance();
boolean neededReconstruction = isDecommission ?
blockManager.isNeededReconstruction(block, num) :
blockManager.isNeededReconstructionForMaintenance(block, num);
@ -723,7 +730,7 @@ private void processBlocksInternal(
// Even if the block is without sufficient redundancy,
// it might not block decommission/maintenance if it
// has sufficient redundancy.
if (isSufficient(block, bc, num, isDecommission)) {
if (isSufficient(block, bc, num, isDecommission, isMaintenance)) {
if (pruneReliableBlocks) {
it.remove();
}

View File

@ -373,6 +373,7 @@ public void testExpectedReplications() throws IOException {
testExpectedReplication(2);
testExpectedReplication(3);
testExpectedReplication(4);
testExpectedReplication(10);
}
private void testExpectedReplication(int replicationFactor)