Source:
public void run() { int numFilesCleaned = 0; long diskSpaceCleaned = 0L; try (Timer.Context t = cleanupRoutineDuration.time()) { final long nowMills = Time.currentTimeMillis(); Set<File> oldLogDirs = selectDirsForCleanup(nowMills); final long nowSecs = TimeUnit.MILLISECONDS.toSeconds(nowMills); SortedSet<File> deadWorkerDirs = getDeadWorkerDirs((int) nowSecs, oldLogDirs); LOG.debug("log cleanup: now={} old log dirs dead worker dirs {}", nowSecs, oldLogDirs.stream().map(File::getName).collect(joining(",")), deadWorkerDirs.stream().map(File::getName).collect(joining(","))); for (File dir : deadWorkerDirs) { String path = dir.getCanonicalPath(); long size = FileUtils.sizeOf(dir); LOG.info("Cleaning up: Removing {}, KB", path, size * 1e-3); try { Utils.forceDelete(path); cleanupEmptyTopoDirectory(dir); numFilesCleaned++; diskSpaceCleaned += size; } catch (Exception ex) { ExceptionMeters.NUM_FILE_REMOVAL_EXCEPTIONS.mark(); LOG.error(ex.getMessage(), ex); } } final List<DirectoryCleaner.DeletionMeta> perWorkerDirCleanupMeta = perWorkerDirCleanup(maxPerWorkerLogsSizeMb * 1024 * 1024); numFilesCleaned += perWorkerDirCleanupMeta.stream().mapToInt(meta -> meta.deletedFiles).sum(); diskSpaceCleaned += perWorkerDirCleanupMeta.stream().mapToLong(meta -> meta.deletedSize).sum(); final DirectoryCleaner.DeletionMeta globalLogCleanupMeta = globalLogCleanup(maxSumWorkerLogsSizeMb * 1024 * 1024); numFilesCleaned += globalLogCleanupMeta.deletedFiles; diskSpaceCleaned += globalLogCleanupMeta.deletedSize; } catch (Exception ex) { ExceptionMeters.NUM_CLEANUP_EXCEPTIONS.mark(); LOG.error("Exception while cleaning up old log.", ex); } numFilesCleanedUp.update(numFilesCleaned); diskSpaceFreed.update(diskSpaceCleaned); }

Target:
public void run() { int numFilesCleaned = 0; long diskSpaceCleaned = 0L; try (Timer.Context t = cleanupRoutineDuration.time()) { final long nowMills = Time.currentTimeMillis(); Set<File> oldLogDirs = selectDirsForCleanup(nowMills); final long nowSecs = TimeUnit.MILLISECONDS.toSeconds(nowMills); SortedSet<File> deadWorkerDirs = getDeadWorkerDirs((int) nowSecs, oldLogDirs); LOG.debug("log cleanup: now={} old log dirs dead worker dirs {}", nowSecs, oldLogDirs.stream().map(File::getName).collect(joining(",")), deadWorkerDirs.stream().map(File::getName).collect(joining(","))); for (File dir : deadWorkerDirs) { String path = dir.getCanonicalPath(); long sizeInBytes = FileUtils.sizeOf(dir); LOG.info("Cleaning up: Removing {}, KB", path, sizeInBytes * 1e-3); try { Utils.forceDelete(path); cleanupEmptyTopoDirectory(dir); numFilesCleaned++; diskSpaceCleaned += sizeInBytes; } catch (Exception ex) { ExceptionMeters.NUM_FILE_REMOVAL_EXCEPTIONS.mark(); LOG.error(ex.getMessage(), ex); } } final List<DeletionMeta> perWorkerDirCleanupMeta = perWorkerDirCleanup(maxPerWorkerLogsSizeMb * 1024 * 1024); numFilesCleaned += perWorkerDirCleanupMeta.stream().mapToInt(meta -> meta.deletedFiles).sum(); diskSpaceCleaned += perWorkerDirCleanupMeta.stream().mapToLong(meta -> meta.deletedSize).sum(); final DeletionMeta globalLogCleanupMeta = globalLogCleanup(maxSumWorkerLogsSizeMb * 1024 * 1024); numFilesCleaned += globalLogCleanupMeta.deletedFiles; diskSpaceCleaned += globalLogCleanupMeta.deletedSize; } catch (Exception ex) { ExceptionMeters.NUM_CLEANUP_EXCEPTIONS.mark(); LOG.error("Exception while cleaning up old log.", ex); } numFilesCleanedUp.update(numFilesCleaned); diskSpaceFreed.update(diskSpaceCleaned); }