void recoverTransitionRead ( DataNode datanode , NamespaceInfo nsInfo , Collection < File > dataDirs , StartupOption startOpt ) throws IOException { assert FSConstants . LAYOUT_VERSION == nsInfo . getLayoutVersion ( ) : "Block-pool and name-node layout versions must be the same." ; // 1. For each Namespace data directory analyze the state and // check whether all is consistent before transitioning. this . storageDirs = new ArrayList < StorageDirectory > ( dataDirs . size ( ) ) ; ArrayList < StorageState > dataDirStates = new ArrayList < StorageState > ( dataDirs . size ( ) ) ; for ( Iterator < File > it = dataDirs . iterator ( ) ; it . hasNext ( ) ; ) { File dataDir = it . next ( ) ; StorageDirectory sd = new StorageDirectory ( dataDir , null , false ) ; StorageState curState ; try { curState = sd . analyzeStorage ( startOpt ) ; // sd is locked but not opened switch ( curState ) { case NORMAL : break ; case NON_EXISTENT : // ignore this storage LOG . info ( "Storage directory " + dataDir + " does not exist." ) ; it . remove ( ) ; continue ; case NOT_FORMATTED : // format LOG . info ( "Storage directory " + dataDir + " is not formatted." ) ; if ( ! sd . isEmpty ( ) ) { LOG . error ( "Storage directory " + dataDir + " is not empty, and will not be formatted! Exiting." ) ; throw new IOException ( "Storage directory " + dataDir + " is not empty!" ) ; } LOG . info ( "Formatting ..." ) ; format ( sd , nsInfo ) ; break ; default : // recovery part is common sd . doRecover ( curState ) ; } } catch ( IOException ioe ) { sd . unlock ( ) ; throw ioe ; } // add to the storage list. This is inherited from parent class, Storage. addStorageDir ( sd ) ; dataDirStates . add ( curState ) ; } if ( dataDirs . size ( ) == 0 ) // none of the data dirs exist throw new IOException ( "All specified directories are not accessible or do not exist." ) ; // 2. Do transitions // Each storage directory is treated individually. // During startup some of them can upgrade or roll back // while others could be up-to-date for the regular startup. doTransition ( datanode , nsInfo , startOpt ) ; // 3. Update all storages. Some of them might have just been formatted. this . writeAll ( ) ; }
Analyze storage directories . Recover from previous transitions if required .