public void markBlockAsCorrupt ( Block blk , DatanodeInfo dn , final boolean parallelInitialBlockReport ) throws IOException { if ( ! parallelInitialBlockReport ) { // regular call, not through parallel block report writeLock ( ) ; } lockParallelBRLock ( parallelInitialBlockReport ) ; try { DatanodeDescriptor node = getDatanode ( dn ) ; if ( node == null ) { throw new IOException ( "Cannot mark block" + blk . getBlockName ( ) + " as corrupt because datanode " + dn . getName ( ) + " does not exist. " ) ; } final BlockInfo storedBlockInfo = blocksMap . getStoredBlock ( blk ) ; if ( storedBlockInfo == null ) { // Check if the replica is in the blockMap, if not // ignore the request for now. This could happen when BlockScanner // thread of Datanode reports bad block before Block reports are sent // by the Datanode on startup NameNode . stateChangeLog . info ( "BLOCK NameSystem.markBlockAsCorrupt: " + "block " + blk + " could not be marked " + "as corrupt as it does not exists in " + "blocksMap" ) ; } else { INodeFile inode = storedBlockInfo . getINode ( ) ; if ( inode == null ) { NameNode . stateChangeLog . info ( "BLOCK NameSystem.markBlockAsCorrupt: " + "block " + blk + " could not be marked " + "as corrupt as it does not belong to " + "any file" ) ; addToInvalidates ( storedBlockInfo , node , false ) ; return ; } // Add this replica to corruptReplicas Map if ( ! corruptReplicas . addToCorruptReplicasMap ( storedBlockInfo , node ) ) { return ; } NumberReplicas num = countNodes ( storedBlockInfo ) ; short blockReplication = inode . getBlockReplication ( storedBlockInfo ) ; if ( num . liveReplicas ( ) > blockReplication ) { // the block is over-replicated so invalidate the replicas immediately invalidateBlock ( storedBlockInfo , node , true ) ; } else if ( isPopulatingReplQueuesInternal ( ) ) { // add the block to neededReplication int numCurrentReplicas = num . liveReplicas ( ) + pendingReplications . getNumReplicas ( storedBlockInfo ) ; updateNeededReplicationQueue ( storedBlockInfo , - 1 , numCurrentReplicas , num . decommissionedReplicas , node , blockReplication ) ; } } } finally { if ( ! parallelInitialBlockReport ) { writeUnlock ( ) ; } unlockParallelBRLock ( parallelInitialBlockReport ) ; } }
Mark the block belonging to datanode as corrupt