Namenode can stuck in safemode on restart if it crashes just after addblock logsync and after taking snapshot for such file. This issue is reported by Prakash and Sathish.
On looking into the issue following things are happening.
1) Client added block at NN and just did logsync
So, NN has block ID persisted.
2)Before returning addblock response to client take a snapshot for root or parent directories for that file
3) Delete parent directory for that file
4) Now crash the NN with out responding success to client for that addBlock call
Now on restart of the Namenode, it will stuck in safemode.