Fix decommission UnsupportedOperationException (#4172)

Reviewed-by: tomscut <litao@bigo.sg>
Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
daimin 2022-04-18 10:40:12 +08:00 committed by GitHub
parent b8c6ba6046
commit 248c548616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -751,8 +751,10 @@ public class DatanodeAdminManager {
// Remove the block from the list if it's no longer in the block map,
// e.g. the containing file has been deleted
if (blockManager.blocksMap.getStoredBlock(block) == null) {
LOG.trace("Removing unknown block {}", block);
it.remove();
if (pruneReliableBlocks) {
LOG.trace("Removing unknown block {}", block);
it.remove();
}
continue;
}

View File

@ -53,6 +53,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.client.HdfsDataInputStream;
import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;
import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.DatanodeID;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo.AdminStates;
@ -61,6 +62,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
@ -668,6 +670,21 @@ public class TestDecommission extends AdminStatesBaseTest {
fdos.close();
}
@Test(timeout = 20000)
public void testDecommissionWithUnknownBlock() throws IOException {
startCluster(1, 3);
FSNamesystem ns = getCluster().getNamesystem(0);
DatanodeManager datanodeManager = ns.getBlockManager().getDatanodeManager();
BlockInfo blk = new BlockInfoContiguous(new Block(1L), (short) 1);
DatanodeDescriptor dn = datanodeManager.getDatanodes().iterator().next();
dn.getStorageInfos()[0].addBlock(blk, blk);
datanodeManager.getDatanodeAdminManager().startDecommission(dn);
waitNodeState(dn, DatanodeInfo.AdminStates.DECOMMISSIONED);
}
private static String scanIntoString(final ByteArrayOutputStream baos) {
final TextStringBuilder sb = new TextStringBuilder();
final Scanner scanner = new Scanner(baos.toString());