static void cleanUpAndCheckBackup ( Configuration conf , File origin ) throws IOException { // get all backups String [ ] backups = getBackups ( origin ) ; File root = origin . getParentFile ( ) ; // maximum total number of backups int copiesToKeep = conf . getInt ( NN_IMAGE_COPIES_TOKEEP , NN_IMAGE_COPIES_TOKEEP_DEFAULT ) ; // days to keep, if set to 0 than keep only last backup int daysToKeep = conf . getInt ( NN_IMAGE_DAYS_TOKEEP , NN_IMAGE_DAYS_TOKEEP_DEFAULT ) ; if ( copiesToKeep == 0 && daysToKeep == 0 ) { // Do not delete anything in this case // every startup will create extra checkpoint return ; } // cleanup copies older than daysToKeep deleteOldBackups ( root , backups , daysToKeep , copiesToKeep ) ; // check remaining backups backups = getBackups ( origin ) ; if ( backups . length >= copiesToKeep ) { throw new IOException ( "Exceeded maximum number of standby backups of " + origin + " under " + origin . getParentFile ( ) + " max: " + copiesToKeep ) ; } }
Check if we have not exceeded the maximum number of backups .