while (true) {
if (sampler.next())
Trace.on("gc");
Span gcSpan = Trace.start("loop");
tStart = System.currentTimeMillis();
try {
// STEP 1: gather candidates
System.gc(); // make room
candidateMemExceeded = false;
checkForBulkProcessingFiles = false;
Span candidatesSpan = Trace.start("getCandidates");
status.current.started = System.currentTimeMillis();
SortedSet<String> candidates = getCandidates();
status.current.candidates = candidates.size();
candidatesSpan.stop();
// STEP 2: confirm deletes
// WARNING: This line is EXTREMELY IMPORTANT.
// You MUST confirm candidates are okay to delete
Span confirmDeletesSpan = Trace.start("confirmDeletes");
confirmDeletes(candidates);
status.current.inUse = status.current.candidates - candidates.size();
confirmDeletesSpan.stop();
// STEP 3: delete files
if (safemode) {
if (verbose)
System.out.println("SAFEMODE: There are " + candidates.size() + " data file candidates marked for deletion.\n"
+ " Examine the log files to identify them.\n" + " They can be removed by executing: bin/accumulo gc --offline\n"
+ "WARNING: Do not run the garbage collector in offline mode unless you are positive\n"
+ " that the accumulo METADATA table is in a clean state, or that accumulo\n"
+ " has not yet been run, in the case of an upgrade.");
log.info("SAFEMODE: Listing all data file candidates for deletion");
for (String s : candidates)
log.info("SAFEMODE: " + s);
log.info("SAFEMODE: End candidates for deletion");
} else {
Span deleteSpan = Trace.start("deleteFiles");
deleteFiles(candidates);
log.info("Number of data file candidates for deletion: " + status.current.candidates);
log.info("Number of data file candidates still in use: " + status.current.inUse);
log.info("Number of successfully deleted data files: " + status.current.deleted);
log.info("Number of data files delete failures: " + status.current.errors);
deleteSpan.stop();
// check bulk dirs we just to deleted files from to see if empty
deleteEmptyBulkDirs(candidates);
}
status.current.finished = System.currentTimeMillis();
status.last = status.current;
status.current = new GcCycleStats();
} catch (Exception e) {
log.error(e, e);
}
tStop = System.currentTimeMillis();
log.info(String.format("Collect cycle took %.2f seconds", ((tStop - tStart) / 1000.0)));
if (offline)
break;
if (candidateMemExceeded) {
log.info("Gathering of candidates was interrupted due to memory shortage. Bypassing cycle delay to collect the remaining candidates.");
continue;
}
// Clean up any unused write-ahead logs
Span waLogs = Trace.start("walogs");
try {
log.info("Beginning garbage collection of write-ahead logs");
GarbageCollectWriteAheadLogs.collect(fs, status);
} catch (Exception e) {
log.error(e, e);
}
waLogs.stop();
gcSpan.stop();
Trace.offNoFlush();
try {
log.debug("Sleeping for " + gcDelay + " milliseconds");