use of org.apache.accumulo.gc.replication.CloseWriteAheadLogReferences in project accumulo by apache.
the class SimpleGarbageCollector method run.
private void run() {
long tStart, tStop;
// Sleep for an initial period, giving the master time to start up and
// old data files to be unused
log.info("Trying to acquire ZooKeeper lock for garbage collector");
try {
getZooLock(startStatsService());
} catch (Exception ex) {
log.error("{}", ex.getMessage(), ex);
System.exit(1);
}
try {
long delay = getStartDelay();
log.debug("Sleeping for {} milliseconds before beginning garbage collection cycles", delay);
Thread.sleep(delay);
} catch (InterruptedException e) {
log.warn("{}", e.getMessage(), e);
return;
}
ProbabilitySampler sampler = new ProbabilitySampler(getConfiguration().getFraction(Property.GC_TRACE_PERCENT));
while (true) {
Trace.on("gc", sampler);
Span gcSpan = Trace.start("loop");
tStart = System.currentTimeMillis();
try {
// make room
System.gc();
status.current.started = System.currentTimeMillis();
new GarbageCollectionAlgorithm().collect(new GCEnv(RootTable.NAME));
new GarbageCollectionAlgorithm().collect(new GCEnv(MetadataTable.NAME));
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);
status.current.finished = System.currentTimeMillis();
status.last = status.current;
status.current = new GcCycleStats();
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
}
tStop = System.currentTimeMillis();
log.info(String.format("Collect cycle took %.2f seconds", ((tStop - tStart) / 1000.0)));
// We want to prune references to fully-replicated WALs from the replication table which are no longer referenced in the metadata table
// before running GarbageCollectWriteAheadLogs to ensure we delete as many files as possible.
Span replSpan = Trace.start("replicationClose");
try {
CloseWriteAheadLogReferences closeWals = new CloseWriteAheadLogReferences(this);
closeWals.run();
} catch (Exception e) {
log.error("Error trying to close write-ahead logs for replication table", e);
} finally {
replSpan.stop();
}
// Clean up any unused write-ahead logs
Span waLogs = Trace.start("walogs");
try {
GarbageCollectWriteAheadLogs walogCollector = new GarbageCollectWriteAheadLogs(this, fs, isUsingTrash());
log.info("Beginning garbage collection of write-ahead logs");
walogCollector.collect(status);
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
} finally {
waLogs.stop();
}
gcSpan.stop();
// we just made a lot of metadata changes: flush them out
try {
Connector connector = getConnector();
connector.tableOperations().compact(MetadataTable.NAME, null, null, true, true);
connector.tableOperations().compact(RootTable.NAME, null, null, true, true);
} catch (Exception e) {
log.warn("{}", e.getMessage(), e);
}
Trace.off();
try {
long gcDelay = getConfiguration().getTimeInMillis(Property.GC_CYCLE_DELAY);
log.debug("Sleeping for {} milliseconds", gcDelay);
Thread.sleep(gcDelay);
} catch (InterruptedException e) {
log.warn("{}", e.getMessage(), e);
return;
}
}
}
Aggregations