private void deleteLeastRecentlyUsedProjects ( long sizeToFreeInBytes , final List < ProjectDirectoryMetadata > projectDirMetadataList ) { // Sort projects by last reference time in ascending order projectDirMetadataList . sort ( Comparator . comparing ( ProjectDirectoryMetadata :: getLastAccessTime ) ) ; final Set < File > projectDirsToDelete = new HashSet <> ( ) ; for ( final ProjectDirectoryMetadata proj : projectDirMetadataList ) { if ( sizeToFreeInBytes > 0 ) { // Delete the project directory even if flow within is running. It's OK to // delete the directory since execution dir is HARD linked to project dir. Note that even // if project is deleted, disk space will be freed up only when all associated execution // dirs are deleted. if ( proj . getInstalledDir ( ) != null ) { projectDirsToDelete . add ( proj . getInstalledDir ( ) ) ; sizeToFreeInBytes -= proj . getDirSizeInByte ( ) ; } } else { break ; } } final long start = System . currentTimeMillis ( ) ; deleteProjectDirsInParallel ( ImmutableSet . copyOf ( projectDirsToDelete ) ) ; final long end = System . currentTimeMillis ( ) ; log . info ( "Deleting {} project dir(s) took {} sec(s)" , projectDirsToDelete . size ( ) , ( end - start ) / 1000 ) ; }
Delete least recently used projects to free up space