diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminManager.java index f2ae4dfbf7..6327b4f254 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeAdminManager.java @@ -345,7 +345,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); @@ -379,6 +381,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(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java index 092b5af2dd..fcff0e2fa4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMaintenanceState.java @@ -373,6 +373,7 @@ public void testExpectedReplications() throws IOException { testExpectedReplication(2); testExpectedReplication(3); testExpectedReplication(4); + testExpectedReplication(10); } private void testExpectedReplication(int replicationFactor)