Now let us get into the details about Namenode Recovery Process. Namenode recovery happens in safe mode.
- Automated Process
- Let us assume that namenode is restarted (we can do it using Cloudera Manager web interface)
- It will start in safe mode. In safe mode, we will not be able to add files to HDFS, but we can read data from some of the files which are being recovered.
- Namenode will pick the latest fsimage from dfs.name.dir and will restore in the memory. Now Namenode will have metadata upto point in time when the fsimage is created.
- Changes to metadata will be available as part of edit logs created since last checkpoint and hence Namenode will play back those edit logs.
- However fsimage and edit logs will only contain partial metadata such as files and blocks, but not block locations.
- As Namenode comes up, datanodes send the information of block locations to Namenode.
- Once fsimage is restored, edit logs are played back and information of block locations are updated, Namenode will come out of safe mode.
- Manual Process (in case of corruption or missing files or directories on namenode) – Login to Namenode and run this command as hdfs
hadoop namenode -recover