HDFS safe mode protects the namespace while the NameNode waits for enough block reports. Operators often meet it when writes fail even though the NameNode daemon is running.
Checking safe mode is read-only. Leaving safe mode manually is a state-changing action and should happen only after block reports and cluster health explain why the NameNode is still waiting.
Do not force safe mode off to hide missing-block or under-replication problems. Confirm DataNodes are live and the health report is acceptable first.
$ hdfs dfsadmin -safemode get Safe mode is ON
$ hdfs dfsadmin -report Live datanodes (3): Dead datanodes (0): Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0
Related: How to check HDFS cluster health
$ hdfs dfsadmin -safemode get Safe mode is ON
$ hdfs dfsadmin -safemode leave Safe mode is OFF
Leaving safe mode early can allow writes while the cluster still has missing or under-replicated blocks.
$ hdfs dfs -mkdir -p /tmp/safemode-check
$ hdfs dfs -rmdir /tmp/safemode-check