static boolean format ( Configuration conf , boolean force , boolean isConfirmationNeeded ) throws IOException { boolean allowFormat = conf . getBoolean ( "dfs.namenode.support.allowformat" , true ) ; if ( ! allowFormat ) { throw new IOException ( "The option dfs.namenode.support.allowformat is " + "set to false for this filesystem, so it " + "cannot be formatted. You will need to set " + "dfs.namenode.support.allowformat parameter " + "to true in order to format this filesystem" ) ; } Collection < URI > dirsToFormat = NNStorageConfiguration . getNamespaceDirs ( conf ) ; Collection < URI > editDirsToFormat = NNStorageConfiguration . getNamespaceEditsDirs ( conf ) ; FSNamesystem nsys = new FSNamesystem ( new FSImage ( conf , dirsToFormat , editDirsToFormat , null ) , conf ) ; try { if ( ! nsys . dir . fsImage . confirmFormat ( force , isConfirmationNeeded ) ) { return true ; // aborted } nsys . dir . fsImage . format ( ) ; return false ; } finally { nsys . close ( ) ; } }
Verify that configured directories exist then Interactively confirm that formatting is desired for each existing directory and format them .