How to Fix Corrupt Blocks And Under Replicated Blocks in HDFS

This post shows ways to fix missing or corrupt blocks in HDFS and under replicated blocks in HDFS.

How to find out corrupt blocks

To list the corrupt blocks in the HDFS you can use the following command.

This command will give you the list of missing blocks and the file name to which those blocks belong. You can also use hdfs fsck / to get information about the file system including corrupt blocks and under replicated blocks.

How to fix corrupt or missing blocks error

There is no easy way to fix the corrupt block error. If you can copy the same file again then that is the best thing to do. For that you can delete the files with corrupt blocks and then copy the file again.

To delete the files having corrupt blocks use the following command.

If you don’t want to delete the file and want to do some inspection of the nodes where the blocks are stored then you can get information about the nodes using the following procedure.

Using the name of the file you got by running this command hdfs fsck -list-corruptfileblocks run the following command to get the DataNode info.

Then you can inspect the node for any network or hardware related problems.

How to fix under replicated blocks

To get the list of under replicated blocks you can run the following command.

It will give you the name of the file, block and the expected/found replicated count. Hadoop framework should replicate the under replicated blocks automatically but you can also write a script to set the replication to the desired number.

Since the output of hdfs fsck / is in the following form –

So you can use the following script to get the file names in which blocks are replicated and store those files in the temp file. Then iterate that temp file and use -setrep command to set the replication to desired number.

That’s all for the topic How to Fix Corrupt Blocks And Under Replicated Blocks in HDFS. If something is missing or you have something to share about the topic please write a comment.


You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.