public class GarbageCollectWriteAheadLogs {
private static final Logger log = Logger.getLogger(GarbageCollectWriteAheadLogs.class);
public static void collect(FileSystem fs, GCStatus status) {
Span span = Trace.start("scanServers");
try {
status.currentLog.started = System.currentTimeMillis();
Map<String,String> fileToServerMap = new HashMap<String,String>();
int count = scanServers(fileToServerMap);
long fileScanStop = System.currentTimeMillis();
log.info(String.format("Fetched %d files from %d servers in %.2f seconds", fileToServerMap.size(), count,
(fileScanStop - status.currentLog.started) / 1000.));
status.currentLog.candidates = fileToServerMap.size();
span.stop();
span = Trace.start("removeMetadataEntries");
try {
count = removeMetadataEntries(fileToServerMap, status);
} catch (Exception ex) {
log.error("Unable to scan metadata table", ex);
return;
} finally {
span.stop();
}
long logEntryScanStop = System.currentTimeMillis();
log.info(String.format("%d log entries scanned in %.2f seconds", count, (logEntryScanStop - fileScanStop) / 1000.));
span = Trace.start("removeFiles");
Map<String,ArrayList<String>> serverToFileMap = mapServersToFiles(fileToServerMap);
count = removeFiles(fs, serverToFileMap, status);
long removeStop = System.currentTimeMillis();
log.info(String.format("%d total logs removed from %d servers in %.2f seconds", count, serverToFileMap.size(), (removeStop - logEntryScanStop) / 1000.));
status.currentLog.finished = removeStop;
status.lastLog = status.currentLog;
status.currentLog = new GcCycleStats();
span.stop();
} catch (Exception e) {
log.error("exception occured while garbage collecting write ahead logs", e);
span.stop();
}
}