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;
}
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();
}
}
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();
}
}
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();
}
}
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;
}
}
Aggregations