Search in sources :

Example 1 with CloseWriteAheadLogReferences

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;
        }
    }
}
Also used : ProbabilitySampler(org.apache.accumulo.core.trace.ProbabilitySampler) CloseWriteAheadLogReferences(org.apache.accumulo.gc.replication.CloseWriteAheadLogReferences) Connector(org.apache.accumulo.core.client.Connector) GcCycleStats(org.apache.accumulo.core.gc.thrift.GcCycleStats) Span(org.apache.accumulo.core.trace.Span) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) FileNotFoundException(java.io.FileNotFoundException) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Connector (org.apache.accumulo.core.client.Connector)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 GcCycleStats (org.apache.accumulo.core.gc.thrift.GcCycleStats)1 ReplicationTableOfflineException (org.apache.accumulo.core.replication.ReplicationTableOfflineException)1 ProbabilitySampler (org.apache.accumulo.core.trace.ProbabilitySampler)1 Span (org.apache.accumulo.core.trace.Span)1 CloseWriteAheadLogReferences (org.apache.accumulo.gc.replication.CloseWriteAheadLogReferences)1 KeeperException (org.apache.zookeeper.KeeperException)1