Solution

Solution for the use case.

Recovery Steps

You can get the list of corrupt blocks using hdfs fsck /. After identifying the corrupt blocks, recover the corrupt blocks:

  1. The Namenode will be in safemode at this point, We can force exit out of safemode to perform the following operations hdfs dfsadmin -safemode forceExit.
  2. At this point the Namenode is out of safemode. You must copy the corrupt file data to a backup file hdfs dfs -cp <corrupt_file> <backup_file>.
  3. Truncate the corrupt file to 0 size hdfs dfs -truncate 0 <corrupt_file>.
  4. Append the backup file to the original corrupt file hdfs dfs -cat <backup_file> | hdfs dfs -appendToFile - <corrupt_file>.