1. Security Mode Overview
Security mode is a special state of HDFs, in which the file system only accepts requests for read data, and does not accept change requests such as deletion and modification, which is a protection mechanism to ensure the security of data blocks in the cluster.
When the Namenode master node is started, HDFs enters Safe mode first, and the cluster begins to check the integrity of the data blocks. Datanode will report the available block information to Namenode when it is launched, and HDFs automatically leaves safe mode when the entire system reaches the security standard.
Assuming that we set the number of replicas (that is, parameter dfs.replication) is 5, then there should be 5 copies on the Datanode, assuming there are only 3 copies, then the scale is 3/5=0.6. A minimum copy of the replica rate (that is, parameter dfs.namenode.safemode.threshold-pct) 0.999 is defined in configuration file Hdfs-default.xml.
Our replica rate of 0.6 is significantly less than 0.99, so the system will automatically replicate to other Datanode, making the replica rate not less than 0.999. If there are 8 replicas in the system, exceeding the 5 copies we set, the system will also delete the extra 3 copies.
If HDFs is in Safe mode, the HDFS client is not allowed to make any modifications to the file, including uploading files, deleting files, renaming, creating folders, modifying the number of copies, and so on.
2. Safe Mode configuration
Key configuration related to Safe mode in the Hdfs-site.xml file, there are several properties:
Dfs.namenode.replication.min: The minimum number of copies per chunk, default is 1. When uploading a file, the minimum number of copies is reached and the upload is considered successful.
dfs.namenode.safemode.threshold-pct: The percentage of data blocks that have reached the minimum number of replicas. The default is 0.999f. When it is smaller than this, it switches the system into Safe mode, replicates the data block, and when it is larger than that, it leaves Safe mode, indicating that the system has enough copies of the data blocks to provide services externally. Less than or equal to 0 means not entering safe mode, greater than 1 means always in safe mode.
Dfs.namenode.safemode.min.datanodes: Minimum number of available datanode required to leave Safe mode, default is 0. That is, even if all datanode are unavailable, you can still leave safe mode.
Dfs.namenode.safemode.extension: When the cluster is available with a block scale and the available Datanode are met, the cluster will leave safe mode if the requirements are met after the extension configured time period. The unit is in milliseconds and defaults to 30000. That is, when the condition is met and can be maintained for 30 seconds, leave safe mode. This configuration is primarily to confirm the stability of the cluster. Avoid meeting the requirements and immediately do not meet the safety standards.
To summarize, to leave Safe mode, the following conditions need to be met:
1) to meet the requirements of the block ratio of the number of copies required;
2) The number of Datanode nodes available to meet the number of configuration requirements;
3) 1, 22 conditions after the maintenance of time to meet the requirements of the configuration
3. Safe Mode Command
Manual access to Safe mode
HDFs Dfsadmin-safemode Enter
Manual access to Safe mode is useful for cluster maintenance or upgrades, because the data on HDFs is read-only at this time. To manually exit Safe mode, you can use the following command:
HDFs Dfsadmin-safemode Leave
If you want to get to the cluster if it is in Safe mode, you can get it using the following command:
HDFs Dfsadmin-safemode Get (can also be viewed in the Web page for Safe mode status)
HDFs Safe Mode