Search in sources :

Example 1 with CompactionStats

use of org.apache.accumulo.server.compaction.CompactionStats in project accumulo by apache.

the class MinorCompactor method call.

@Override
public CompactionStats call() {
    final String outputFileName = getOutputFile();
    log.trace("Begin minor compaction {} {}", outputFileName, getExtent());
    // output to new MapFile with a temporary name
    int sleepTime = 100;
    double growthFactor = 4;
    // 3 minutes
    int maxSleepTime = 1000 * 60 * 3;
    boolean reportedProblem = false;
    int retryCounter = 0;
    runningCompactions.add(this);
    try {
        do {
            try {
                CompactionStats ret = super.call();
                if (reportedProblem) {
                    ProblemReports.getInstance(tabletServer.getContext()).deleteProblemReport(getExtent().tableId(), ProblemType.FILE_WRITE, outputFileName);
                }
                return ret;
            } catch (IOException | UnsatisfiedLinkError e) {
                log.warn("MinC failed ({}) to create {} retrying ...", e.getMessage(), outputFileName);
                ProblemReports.getInstance(tabletServer.getContext()).report(new ProblemReport(getExtent().tableId(), ProblemType.FILE_WRITE, outputFileName, e));
                reportedProblem = true;
            } catch (RuntimeException | NoClassDefFoundError e) {
                // if this is coming from a user iterator, it is possible that the user could change the
                // iterator config and that the minor compaction would succeed
                // If the minor compaction stalls for too long during recovery, it can interfere with
                // other tables loading
                // Throw exception if this happens so assignments can be rescheduled.
                ProblemReports.getInstance(tabletServer.getContext()).report(new ProblemReport(getExtent().tableId(), ProblemType.FILE_WRITE, outputFileName, e));
                if (retryCounter >= 4 && mincReason.equals(MinorCompactionReason.RECOVERY)) {
                    log.warn("MinC ({}) is stuck for too long during recovery, throwing error to reschedule.", getExtent(), e);
                    throw new RuntimeException(e);
                }
                log.warn("MinC failed ({}) to create {} retrying ...", e.getMessage(), outputFileName, e);
                reportedProblem = true;
                retryCounter++;
            } catch (CompactionCanceledException e) {
                throw new IllegalStateException(e);
            }
            int sleep = sleepTime + random.nextInt(sleepTime);
            log.debug("MinC failed sleeping {} ms before retrying", sleep);
            sleepUninterruptibly(sleep, TimeUnit.MILLISECONDS);
            sleepTime = (int) Math.round(Math.min(maxSleepTime, sleepTime * growthFactor));
            // clean up
            try {
                if (getVolumeManager().exists(new Path(outputFileName))) {
                    getVolumeManager().deleteRecursively(new Path(outputFileName));
                }
            } catch (IOException e) {
                log.warn("Failed to delete failed MinC file {} {}", outputFileName, e.getMessage());
            }
            if (isTableDeleting())
                return new CompactionStats(0, 0);
        } while (true);
    } finally {
        thread = null;
        runningCompactions.remove(this);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) IOException(java.io.IOException) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) ProblemReport(org.apache.accumulo.server.problems.ProblemReport)

Example 2 with CompactionStats

use of org.apache.accumulo.server.compaction.CompactionStats in project accumulo by apache.

the class CompactableImpl method compact.

@Override
public void compact(CompactionServiceId service, CompactionJob job, RateLimiter readLimiter, RateLimiter writeLimiter, long queuedTime) {
    Optional<CompactionInfo> ocInfo = reserveFilesForCompaction(service, job);
    if (ocInfo.isEmpty())
        return;
    var cInfo = ocInfo.get();
    StoredTabletFile newFile = null;
    long startTime = System.currentTimeMillis();
    CompactionKind kind = job.getKind();
    CompactionStats stats = new CompactionStats();
    try {
        TabletLogger.compacting(getExtent(), job, cInfo.localCompactionCfg);
        tablet.incrementStatusMajor();
        var check = new CompactionCheck(service, kind, cInfo.checkCompactionId);
        TabletFile tmpFileName = tablet.getNextMapFilenameForMajc(cInfo.propagateDeletes);
        var compactEnv = new MajCEnv(kind, check, readLimiter, writeLimiter, cInfo.propagateDeletes);
        SortedMap<StoredTabletFile, DataFileValue> allFiles = tablet.getDatafiles();
        HashMap<StoredTabletFile, DataFileValue> compactFiles = new HashMap<>();
        cInfo.jobFiles.forEach(file -> compactFiles.put(file, allFiles.get(file)));
        stats = CompactableUtils.compact(tablet, job, cInfo, compactEnv, compactFiles, tmpFileName);
        newFile = CompactableUtils.bringOnline(tablet.getDatafileManager(), cInfo, stats, compactFiles, allFiles, kind, tmpFileName);
        TabletLogger.compacted(getExtent(), job, newFile);
    } catch (CompactionCanceledException cce) {
        log.debug("Compaction canceled {} ", getExtent());
    } catch (Exception e) {
        newFile = null;
        throw new RuntimeException(e);
    } finally {
        completeCompaction(job, cInfo.jobFiles, newFile);
        tablet.updateTimer(MAJOR, queuedTime, startTime, stats.getEntriesRead(), newFile == null);
    }
}
Also used : DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) UncheckedIOException(java.io.UncheckedIOException) CompactionCanceledException(org.apache.accumulo.server.compaction.FileCompactor.CompactionCanceledException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) CompactionKind(org.apache.accumulo.core.spi.compaction.CompactionKind) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile) CompactionCanceledException(org.apache.accumulo.server.compaction.FileCompactor.CompactionCanceledException)

Example 3 with CompactionStats

use of org.apache.accumulo.server.compaction.CompactionStats in project accumulo by apache.

the class Tablet method minorCompact.

DataFileValue minorCompact(InMemoryMap memTable, TabletFile tmpDatafile, TabletFile newDatafile, long queued, CommitSession commitSession, long flushId, MinorCompactionReason mincReason) {
    boolean failed = false;
    long start = System.currentTimeMillis();
    timer.incrementStatusMinor();
    long count = 0;
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("Minor compacting " + this.extent);
        CompactionStats stats;
        Span span = TraceUtil.startSpan(this.getClass(), "minorCompact::write");
        try (Scope scope = span.makeCurrent()) {
            count = memTable.getNumEntries();
            MinorCompactor compactor = new MinorCompactor(tabletServer, this, memTable, tmpDatafile, mincReason, tableConfiguration);
            stats = compactor.call();
        } catch (Exception e) {
            TraceUtil.setException(span, e, true);
            throw e;
        } finally {
            span.end();
        }
        Span span2 = TraceUtil.startSpan(this.getClass(), "minorCompact::bringOnline");
        try (Scope scope = span2.makeCurrent()) {
            var storedFile = getDatafileManager().bringMinorCompactionOnline(tmpDatafile, newDatafile, new DataFileValue(stats.getFileSize(), stats.getEntriesWritten()), commitSession, flushId);
            storedFile.ifPresent(stf -> compactable.filesAdded(true, List.of(stf)));
        } catch (Exception e) {
            TraceUtil.setException(span2, e, true);
            throw e;
        } finally {
            span2.end();
        }
        return new DataFileValue(stats.getFileSize(), stats.getEntriesWritten());
    } catch (Exception | Error e) {
        failed = true;
        throw new RuntimeException("Exception occurred during minor compaction on " + extent, e);
    } finally {
        Thread.currentThread().setName(oldName);
        try {
            getTabletMemory().finalizeMinC();
        } catch (Exception t) {
            log.error("Failed to free tablet memory on {}", extent, t);
        }
        if (!failed) {
            lastMinorCompactionFinishTime = System.currentTimeMillis();
        }
        TabletServerMinCMetrics minCMetrics = getTabletServer().getMinCMetrics();
        minCMetrics.addActive(lastMinorCompactionFinishTime - start);
        timer.updateTime(Operation.MINOR, queued, start, count, failed);
        minCMetrics.addQueued(start - queued);
    }
}
Also used : DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) Span(io.opentelemetry.api.trace.Span) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) FileNotFoundException(java.io.FileNotFoundException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) TabletServerMinCMetrics(org.apache.accumulo.tserver.metrics.TabletServerMinCMetrics) Scope(io.opentelemetry.context.Scope)

Aggregations

IOException (java.io.IOException)3 CompactionStats (org.apache.accumulo.server.compaction.CompactionStats)3 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2 Span (io.opentelemetry.api.trace.Span)1 Scope (io.opentelemetry.context.Scope)1 FileNotFoundException (java.io.FileNotFoundException)1 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IterationInterruptedException (org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException)1 StoredTabletFile (org.apache.accumulo.core.metadata.StoredTabletFile)1 TabletFile (org.apache.accumulo.core.metadata.TabletFile)1 CompactionKind (org.apache.accumulo.core.spi.compaction.CompactionKind)1 CompactionCanceledException (org.apache.accumulo.server.compaction.FileCompactor.CompactionCanceledException)1 TooManyFilesException (org.apache.accumulo.server.fs.TooManyFilesException)1 ProblemReport (org.apache.accumulo.server.problems.ProblemReport)1 TabletServerMinCMetrics (org.apache.accumulo.tserver.metrics.TabletServerMinCMetrics)1 DecoderException (org.apache.commons.codec.DecoderException)1 Path (org.apache.hadoop.fs.Path)1