Search in sources :

Example 31 with Span

use of org.apache.accumulo.core.trace.Span in project accumulo by apache.

the class Tablet method majorCompact.

// END PRIVATE METHODS RELATED TO MAJOR COMPACTION
/**
 * Performs a major compaction on the tablet. If needsSplit() returns true, the tablet is split and a reference to the new tablet is returned.
 */
CompactionStats majorCompact(MajorCompactionReason reason, long queued) {
    CompactionStats majCStats = null;
    boolean success = false;
    long start = System.currentTimeMillis();
    timer.incrementStatusMajor();
    synchronized (this) {
        // check that compaction is still needed - defer to splitting
        majorCompactionQueued.remove(reason);
        if (isClosing() || isClosed() || !needsMajorCompaction(reason) || isMajorCompactionRunning() || needsSplit()) {
            return null;
        }
        majorCompactionState = CompactionState.WAITING_TO_START;
    }
    Span span = null;
    try {
        double tracePercent = tabletServer.getConfiguration().getFraction(Property.TSERV_MAJC_TRACE_PERCENT);
        ProbabilitySampler sampler = new ProbabilitySampler(tracePercent);
        span = Trace.on("majorCompaction", sampler);
        majCStats = _majorCompact(reason);
        if (reason == MajorCompactionReason.CHOP) {
            MetadataTableUtil.chopped(getTabletServer(), getExtent(), this.getTabletServer().getLock());
            getTabletServer().enqueueMasterMessage(new TabletStatusMessage(TabletLoadState.CHOPPED, extent));
        }
        success = true;
    } catch (CompactionCanceledException cce) {
        log.debug("Major compaction canceled, extent = {}", getExtent());
    } catch (IOException ioe) {
        log.error("MajC Failed, extent = " + getExtent(), ioe);
    } catch (RuntimeException e) {
        log.error("MajC Unexpected exception, extent = " + getExtent(), e);
    } finally {
        // when an exception is thrown
        synchronized (this) {
            majorCompactionState = null;
            this.notifyAll();
        }
        if (span != null) {
            span.data("extent", "" + getExtent());
            if (majCStats != null) {
                span.data("read", "" + majCStats.getEntriesRead());
                span.data("written", "" + majCStats.getEntriesWritten());
            }
            span.stop();
        }
    }
    long count = 0;
    if (majCStats != null)
        count = majCStats.getEntriesRead();
    timer.updateTime(Operation.MAJOR, queued, start, count, !success);
    return majCStats;
}
Also used : ProbabilitySampler(org.apache.accumulo.core.trace.ProbabilitySampler) TabletStatusMessage(org.apache.accumulo.tserver.mastermessage.TabletStatusMessage) CompactionCanceledException(org.apache.accumulo.tserver.tablet.Compactor.CompactionCanceledException) IOException(java.io.IOException) Span(org.apache.accumulo.core.trace.Span)

Example 32 with Span

use of org.apache.accumulo.core.trace.Span in project accumulo by apache.

the class StatusMaker method run.

public void run() {
    Span span = Trace.start("replicationStatusMaker");
    try {
        // Read from a source table (typically accumulo.metadata)
        final Scanner s;
        try {
            s = conn.createScanner(sourceTableName, Authorizations.EMPTY);
        } catch (TableNotFoundException e) {
            throw new RuntimeException(e);
        }
        // Only pull replication records
        s.fetchColumnFamily(ReplicationSection.COLF);
        s.setRange(ReplicationSection.getRange());
        Text file = new Text();
        for (Entry<Key, Value> entry : s) {
            // Get a writer to the replication table
            if (null == replicationWriter) {
                // Ensures table is online
                try {
                    ReplicationTable.setOnline(conn);
                    replicationWriter = ReplicationTable.getBatchWriter(conn);
                } catch (ReplicationTableOfflineException | AccumuloSecurityException | AccumuloException e) {
                    log.warn("Replication table did not come online");
                    replicationWriter = null;
                    return;
                }
            }
            // Extract the useful bits from the status key
            MetadataSchema.ReplicationSection.getFile(entry.getKey(), file);
            Table.ID tableId = MetadataSchema.ReplicationSection.getTableId(entry.getKey());
            Status status;
            try {
                status = Status.parseFrom(entry.getValue().get());
            } catch (InvalidProtocolBufferException e) {
                log.warn("Could not deserialize protobuf for {}", file);
                continue;
            }
            log.debug("Creating replication status record for {} on table {} with {}.", file, tableId, ProtobufUtil.toString(status));
            Span workSpan = Trace.start("createStatusMutations");
            try {
                // Create entries in the replication table from the metadata table
                if (!addStatusRecord(file, tableId, entry.getValue())) {
                    continue;
                }
            } finally {
                workSpan.stop();
            }
            if (status.getClosed()) {
                Span orderSpan = Trace.start("recordStatusOrder");
                try {
                    if (!addOrderRecord(file, tableId, status, entry.getValue())) {
                        continue;
                    }
                } finally {
                    orderSpan.stop();
                }
                Span deleteSpan = Trace.start("deleteClosedStatus");
                try {
                    deleteStatusRecord(entry.getKey());
                } finally {
                    deleteSpan.stop();
                }
            }
        }
    } finally {
        span.stop();
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) Scanner(org.apache.accumulo.core.client.Scanner) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Text(org.apache.hadoop.io.Text) Span(org.apache.accumulo.core.trace.Span) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Value(org.apache.accumulo.core.data.Value) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) Key(org.apache.accumulo.core.data.Key)

Example 33 with Span

use of org.apache.accumulo.core.trace.Span in project accumulo by apache.

the class WorkMaker method run.

public void run() {
    if (!ReplicationTable.isOnline(conn)) {
        log.debug("Replication table is not yet online");
        return;
    }
    Span span = Trace.start("replicationWorkMaker");
    try {
        final Scanner s;
        try {
            s = ReplicationTable.getScanner(conn);
            if (null == writer) {
                setBatchWriter(ReplicationTable.getBatchWriter(conn));
            }
        } catch (ReplicationTableOfflineException e) {
            log.warn("Replication table was online, but not anymore");
            writer = null;
            return;
        }
        // Only pull records about data that has been ingested and is ready for replication
        StatusSection.limit(s);
        TableConfiguration tableConf;
        Text file = new Text();
        for (Entry<Key, Value> entry : s) {
            // Extract the useful bits from the status key
            ReplicationSchema.StatusSection.getFile(entry.getKey(), file);
            Table.ID tableId = ReplicationSchema.StatusSection.getTableId(entry.getKey());
            log.debug("Processing replication status record for {} on table {}", file, tableId);
            Status status;
            try {
                status = Status.parseFrom(entry.getValue().get());
            } catch (InvalidProtocolBufferException e) {
                log.error("Could not parse protobuf for {} from table {}", file, tableId);
                continue;
            }
            // TODO put this into a filter on serverside
            if (!shouldCreateWork(status)) {
                log.debug("Not creating work: {}", status.toString());
                continue;
            }
            // Get the table configuration for the table specified by the status record
            tableConf = context.getServerConfigurationFactory().getTableConfiguration(tableId);
            // getTableConfiguration(String) returns null if the table no longer exists
            if (null == tableConf) {
                continue;
            }
            // Pull the relevant replication targets
            // TODO Cache this instead of pulling it every time
            Map<String, String> replicationTargets = getReplicationTargets(tableConf);
            // -- Another scanner over the WorkSection can make this relatively cheap
            if (!replicationTargets.isEmpty()) {
                Span workSpan = Trace.start("createWorkMutations");
                try {
                    addWorkRecord(file, entry.getValue(), replicationTargets, tableId);
                } finally {
                    workSpan.stop();
                }
            } else {
                log.warn("No configured targets for table with ID {}", tableId);
            }
        }
    } finally {
        span.stop();
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) Scanner(org.apache.accumulo.core.client.Scanner) Table(org.apache.accumulo.core.client.impl.Table) ReplicationTable(org.apache.accumulo.core.replication.ReplicationTable) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Text(org.apache.hadoop.io.Text) Span(org.apache.accumulo.core.trace.Span) Value(org.apache.accumulo.core.data.Value) ReplicationTableOfflineException(org.apache.accumulo.core.replication.ReplicationTableOfflineException) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) Key(org.apache.accumulo.core.data.Key)

Example 34 with Span

use of org.apache.accumulo.core.trace.Span in project accumulo by apache.

the class TabletServerBatchWriter method close.

public synchronized void close() throws MutationsRejectedException {
    if (closed)
        return;
    Span span = Trace.start("close");
    try {
        closed = true;
        startProcessing();
        waitRTE(new WaitCondition() {

            @Override
            public boolean shouldWait() {
                return totalMemUsed > 0 && !somethingFailed;
            }
        });
        logStats();
        checkForFailures();
    } finally {
        // make a best effort to release these resources
        writer.binningThreadPool.shutdownNow();
        writer.sendThreadPool.shutdownNow();
        jtimer.cancel();
        span.stop();
    }
}
Also used : Span(org.apache.accumulo.core.trace.Span)

Example 35 with Span

use of org.apache.accumulo.core.trace.Span in project accumulo by apache.

the class TabletServerBatchWriter method flush.

public synchronized void flush() throws MutationsRejectedException {
    if (closed)
        throw new IllegalStateException("Closed");
    Span span = Trace.start("flush");
    try {
        checkForFailures();
        if (flushing) {
            // some other thread is currently flushing, so wait
            waitRTE(new WaitCondition() {

                @Override
                public boolean shouldWait() {
                    return flushing && !somethingFailed;
                }
            });
            checkForFailures();
            return;
        }
        flushing = true;
        startProcessing();
        checkForFailures();
        waitRTE(new WaitCondition() {

            @Override
            public boolean shouldWait() {
                return totalMemUsed > 0 && !somethingFailed;
            }
        });
        flushing = false;
        this.notifyAll();
        checkForFailures();
    } finally {
        span.stop();
    // somethingFailed = false;
    }
}
Also used : Span(org.apache.accumulo.core.trace.Span)

Aggregations

Span (org.apache.accumulo.core.trace.Span)56 Key (org.apache.accumulo.core.data.Key)12 Value (org.apache.accumulo.core.data.Value)12 IOException (java.io.IOException)11 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)10 Text (org.apache.hadoop.io.Text)9 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)6 PartialKey (org.apache.accumulo.core.data.PartialKey)6 Mutation (org.apache.accumulo.core.data.Mutation)5 IndexHint (org.vertexium.search.IndexHint)5 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 Connector (org.apache.accumulo.core.client.Connector)4 Scanner (org.apache.accumulo.core.client.Scanner)4 ReplicationTableOfflineException (org.apache.accumulo.core.replication.ReplicationTableOfflineException)4 Status (org.apache.accumulo.server.replication.proto.Replication.Status)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)3