Safe Mode, also known as NameNode Safe Mode, is a maintenance state in the Hadoop Distributed File System (HDFS) where the NameNode, which is the master node, doesn’t allow any changes to the file system metadata. It is a safety mechanism that prevents accidental data loss or corruption and provides an opportunity for system administrators to perform maintenance tasks or troubleshoot issues.
Some key features of Safe Mode are:
1. Read-only access: During Safe Mode, the file system can only be accessed for read operations, such as reading files or listing directories. Write operations, like creating or deleting files, are not allowed.
2. Block replication: Safe Mode ensures that all blocks in the HDFS have the required number of replicas before it starts to accept changes to the metadata. If the replication factor is not met, the NameNode will wait until the blocks are sufficiently replicated to proceed.
3. Manual or automatic trigger: Safe Mode can be triggered manually by an administrator for maintenance purposes, or it can be triggered automatically during the startup of NameNode, when the NameNode detects a low number of DataNodes. After startup, the NameNode will exit Safe Mode once a certain threshold of DataNodes have reported their status, and the replication factor is met for all blocks.
An example of when Safe Mode would be useful is when an administrator wants to perform routine maintenance, like upgrading or adding new DataNodes, without the risk of data loss or corruption.
To enable or disable Safe Mode, the following commands can be used:
Enable Safe Mode:
hadoop dfsadmin -safemode enter
Disable Safe Mode:
hadoop dfsadmin -safemode leave
Check Safe Mode status:
hadoop dfsadmin -safemode get