Search in sources :

Example 56 with TraceScope

use of org.apache.htrace.core.TraceScope in project hadoop by apache.

the class FSOutputSummer method writeChecksumChunks.

/** Generate checksums for the given data chunks and output chunks & checksums
   * to the underlying output stream.
   */
private void writeChecksumChunks(byte[] b, int off, int len) throws IOException {
    sum.calculateChunkedSums(b, off, len, checksum, 0);
    TraceScope scope = createWriteTraceScope();
    try {
        for (int i = 0; i < len; i += sum.getBytesPerChecksum()) {
            int chunkLen = Math.min(sum.getBytesPerChecksum(), len - i);
            int ckOffset = i / sum.getBytesPerChecksum() * getChecksumSize();
            writeChunk(b, off + i, chunkLen, checksum, ckOffset, getChecksumSize());
        }
    } finally {
        if (scope != null) {
            scope.close();
        }
    }
}
Also used : TraceScope(org.apache.htrace.core.TraceScope)

Example 57 with TraceScope

use of org.apache.htrace.core.TraceScope in project cxf by apache.

the class AbstractHTraceClientProvider method startTraceSpan.

protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, String path, String method) {
    Span span = Tracer.getCurrentSpan();
    TraceScope traceScope = null;
    if (span == null) {
        traceScope = tracer.newScope(buildSpanDescription(path, method));
        span = traceScope.getSpan();
    }
    if (span != null) {
        final String spanIdHeader = getSpanIdHeader();
        // Transfer tracing headers into the response headers
        requestHeaders.put(spanIdHeader, Collections.singletonList(span.getSpanId().toString()));
    }
    // In case of asynchronous client invocation, the span should be detached as JAX-RS
    // client request / response filters are going to be executed in different threads.
    boolean detached = false;
    if (isAsyncInvocation() && traceScope != null) {
        traceScope.detach();
        detached = true;
    }
    return new TraceScopeHolder<TraceScope>(traceScope, detached);
}
Also used : TraceScope(org.apache.htrace.core.TraceScope) Span(org.apache.htrace.core.Span)

Example 58 with TraceScope

use of org.apache.htrace.core.TraceScope in project cxf by apache.

the class AbstractHTraceClientProvider method stopTraceSpan.

protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder) {
    if (holder == null) {
        return;
    }
    final TraceScope scope = holder.getScope();
    if (scope != null) {
        // in another thread and should be re-attached to the current one.
        if (holder.isDetached()) {
            scope.reattach();
            scope.close();
        } else {
            scope.close();
        }
    }
}
Also used : TraceScope(org.apache.htrace.core.TraceScope)

Example 59 with TraceScope

use of org.apache.htrace.core.TraceScope in project cxf by apache.

the class AbstractHTraceProvider method stopTraceSpan.

protected void stopTraceSpan(final Map<String, List<String>> requestHeaders, final Map<String, List<Object>> responseHeaders, final TraceScopeHolder<TraceScope> holder) {
    final String spanIdHeader = getSpanIdHeader();
    // Transfer tracing headers into the response headers
    if (requestHeaders.containsKey(spanIdHeader)) {
        responseHeaders.put(spanIdHeader, CastUtils.cast(requestHeaders.get(spanIdHeader)));
    }
    if (holder == null) {
        return;
    }
    final TraceScope span = holder.getScope();
    if (span != null) {
        // one.
        if (holder.isDetached()) {
            span.reattach();
            span.close();
        } else {
            span.close();
        }
    }
}
Also used : TraceScope(org.apache.htrace.core.TraceScope)

Example 60 with TraceScope

use of org.apache.htrace.core.TraceScope in project cxf by apache.

the class AbstractHTraceProvider method startTraceSpan.

protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, String path, String method) {
    // Try to extract the Span Id value from the request header
    final SpanId spanId = getFirstValueOrDefault(requestHeaders, getSpanIdHeader(), SpanId.INVALID);
    TraceScope traceScope = null;
    if (SpanId.INVALID.equals(spanId)) {
        traceScope = tracer.newScope(buildSpanDescription(path, method));
    } else {
        traceScope = tracer.newScope(buildSpanDescription(path, method), spanId);
    }
    // If the service resource is using asynchronous processing mode, the trace
    // scope will be closed in another thread and as such should be detached.
    boolean detached = false;
    if (isAsyncResponse()) {
        traceScope.detach();
        propagateContinuationSpan(traceScope);
        detached = true;
    }
    return new TraceScopeHolder<TraceScope>(traceScope, detached);
}
Also used : TraceScope(org.apache.htrace.core.TraceScope) SpanId(org.apache.htrace.core.SpanId)

Aggregations

TraceScope (org.apache.htrace.core.TraceScope)62 IOException (java.io.IOException)11 InterruptedIOException (java.io.InterruptedIOException)7 MultipleIOException (org.apache.hadoop.io.MultipleIOException)6 RemoteException (org.apache.hadoop.ipc.RemoteException)5 FileNotFoundException (java.io.FileNotFoundException)4 List (java.util.List)4 SnapshotAccessControlException (org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException)4 UnresolvedPathException (org.apache.hadoop.hdfs.protocol.UnresolvedPathException)4 AccessControlException (org.apache.hadoop.security.AccessControlException)4 ClosedChannelException (java.nio.channels.ClosedChannelException)3 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)3 ParentNotDirectoryException (org.apache.hadoop.fs.ParentNotDirectoryException)3 DSQuotaExceededException (org.apache.hadoop.hdfs.protocol.DSQuotaExceededException)3 NSQuotaExceededException (org.apache.hadoop.hdfs.protocol.NSQuotaExceededException)3 QuotaByStorageTypeExceededException (org.apache.hadoop.hdfs.protocol.QuotaByStorageTypeExceededException)3 SpanId (org.apache.htrace.core.SpanId)3 Tracer (org.apache.htrace.core.Tracer)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2