Java Code Examples for org.apache.htrace.Trace#isTracing()

The following examples show how to use org.apache.htrace.Trace#isTracing() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static RpcRequestHeaderProto makeRpcRequestHeader(RPC.RpcKind rpcKind,
    RpcRequestHeaderProto.OperationProto operation, int callId,
    int retryCount, byte[] uuid) {
  RpcRequestHeaderProto.Builder result = RpcRequestHeaderProto.newBuilder();
  result.setRpcKind(convert(rpcKind)).setRpcOp(operation).setCallId(callId)
      .setRetryCount(retryCount).setClientId(ByteString.copyFrom(uuid));

  // Add tracing info if we are currently tracing.
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    result.setTraceInfo(RPCTraceInfoProto.newBuilder()
        .setParentId(s.getSpanId())
        .setTraceId(s.getTraceId()).build());
  }

  return result.build();
}
 
Example 2
Source File: WritableRpcEngine.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable {
  long startTime = 0;
  if (LOG.isDebugEnabled()) {
    startTime = Time.now();
  }
  TraceScope traceScope = null;
  if (Trace.isTracing()) {
    traceScope = Trace.startSpan(RpcClientUtil.methodToTraceString(method));
  }
  ObjectWritable value;
  try {
    value = (ObjectWritable)
      client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args),
        remoteId, fallbackToSimpleAuth);
  } finally {
    if (traceScope != null) traceScope.close();
  }
  if (LOG.isDebugEnabled()) {
    long callTime = Time.now() - startTime;
    LOG.debug("Call: " + method.getName() + " " + callTime);
  }
  return value.get();
}
 
Example 3
Source File: ProtoUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static RpcRequestHeaderProto makeRpcRequestHeader(RPC.RpcKind rpcKind,
    RpcRequestHeaderProto.OperationProto operation, int callId,
    int retryCount, byte[] uuid) {
  RpcRequestHeaderProto.Builder result = RpcRequestHeaderProto.newBuilder();
  result.setRpcKind(convert(rpcKind)).setRpcOp(operation).setCallId(callId)
      .setRetryCount(retryCount).setClientId(ByteString.copyFrom(uuid));

  // Add tracing info if we are currently tracing.
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    result.setTraceInfo(RPCTraceInfoProto.newBuilder()
        .setParentId(s.getSpanId())
        .setTraceId(s.getTraceId()).build());
  }

  return result.build();
}
 
Example 4
Source File: WritableRpcEngine.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable {
  long startTime = 0;
  if (LOG.isDebugEnabled()) {
    startTime = Time.now();
  }
  TraceScope traceScope = null;
  if (Trace.isTracing()) {
    traceScope = Trace.startSpan(RpcClientUtil.methodToTraceString(method));
  }
  ObjectWritable value;
  try {
    value = (ObjectWritable)
      client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args),
        remoteId, fallbackToSimpleAuth);
  } finally {
    if (traceScope != null) traceScope.close();
  }
  if (LOG.isDebugEnabled()) {
    long callTime = Time.now() - startTime;
    LOG.debug("Call: " + method.getName() + " " + callTime);
  }
  return value.get();
}
 
Example 5
Source File: Sender.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseShortCircuitFds(SlotId slotId) throws IOException {
  ReleaseShortCircuitAccessRequestProto.Builder builder =
      ReleaseShortCircuitAccessRequestProto.newBuilder().
      setSlotId(PBHelper.convert(slotId));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ReleaseShortCircuitAccessRequestProto proto = builder.build();
  send(out, Op.RELEASE_SHORT_CIRCUIT_FDS, proto);
}
 
Example 6
Source File: Sender.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void requestShortCircuitShm(String clientName) throws IOException {
  ShortCircuitShmRequestProto.Builder builder =
      ShortCircuitShmRequestProto.newBuilder().
      setClientName(clientName);
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ShortCircuitShmRequestProto proto = builder.build();
  send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto);
}
 
Example 7
Source File: DataTransferProtoUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
static BaseHeaderProto buildBaseHeader(ExtendedBlock blk,
    Token<BlockTokenIdentifier> blockToken) {
  BaseHeaderProto.Builder builder =  BaseHeaderProto.newBuilder()
    .setBlock(PBHelper.convert(blk))
    .setToken(PBHelper.convert(blockToken));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId())
        .setParentId(s.getSpanId()));
  }
  return builder.build();
}
 
Example 8
Source File: Sender.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseShortCircuitFds(SlotId slotId) throws IOException {
  ReleaseShortCircuitAccessRequestProto.Builder builder =
      ReleaseShortCircuitAccessRequestProto.newBuilder().
      setSlotId(PBHelper.convert(slotId));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ReleaseShortCircuitAccessRequestProto proto = builder.build();
  send(out, Op.RELEASE_SHORT_CIRCUIT_FDS, proto);
}
 
Example 9
Source File: Sender.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void requestShortCircuitShm(String clientName) throws IOException {
  ShortCircuitShmRequestProto.Builder builder =
      ShortCircuitShmRequestProto.newBuilder().
      setClientName(clientName);
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId()).setParentId(s.getSpanId()));
  }
  ShortCircuitShmRequestProto proto = builder.build();
  send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto);
}
 
Example 10
Source File: DataTransferProtoUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
static BaseHeaderProto buildBaseHeader(ExtendedBlock blk,
    Token<BlockTokenIdentifier> blockToken) {
  BaseHeaderProto.Builder builder =  BaseHeaderProto.newBuilder()
    .setBlock(PBHelper.convert(blk))
    .setToken(PBHelper.convert(blockToken));
  if (Trace.isTracing()) {
    Span s = Trace.currentSpan();
    builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder()
        .setTraceId(s.getTraceId())
        .setParentId(s.getSpanId()));
  }
  return builder.build();
}
 
Example 11
Source File: LockManager.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Lock the row or throw otherwise
 * @param rowKey the row key
 * @return RowLock used to eventually release the lock 
 * @throws TimeoutIOException if the lock could not be acquired within the
 * allowed rowLockWaitDuration and InterruptedException if interrupted while
 * waiting to acquire lock.
 */
public RowLock lockRow(ImmutableBytesPtr rowKey, int waitDuration) throws IOException {
    RowLockContext rowLockContext = null;
    RowLockImpl result = null;
    TraceScope traceScope = null;

    // If we're tracing start a span to show how long this took.
    if (Trace.isTracing()) {
        traceScope = Trace.startSpan("LockManager.getRowLock");
        traceScope.getSpan().addTimelineAnnotation("Getting a lock");
    }

    boolean success = false;
    try {
        // Keep trying until we have a lock or error out.
        // TODO: do we need to add a time component here?
        while (result == null) {

            // Try adding a RowLockContext to the lockedRows.
            // If we can add it then there's no other transactions currently running.
            rowLockContext = new RowLockContext(rowKey);
            RowLockContext existingContext = lockedRows.putIfAbsent(rowKey, rowLockContext);

            // if there was a running transaction then there's already a context.
            if (existingContext != null) {
                rowLockContext = existingContext;
            }

            result = rowLockContext.newRowLock();
        }
        if (!result.getLock().tryLock(waitDuration, TimeUnit.MILLISECONDS)) {
            if (traceScope != null) {
                traceScope.getSpan().addTimelineAnnotation("Failed to get row lock");
            }
            throw new TimeoutIOException("Timed out waiting for lock for row: " + rowKey);
        }
        rowLockContext.setThreadName(Thread.currentThread().getName());
        success = true;
        return result;
    } catch (InterruptedException ie) {
        LOGGER.warn("Thread interrupted waiting for lock on row: " + rowKey);
        InterruptedIOException iie = new InterruptedIOException();
        iie.initCause(ie);
        if (traceScope != null) {
            traceScope.getSpan().addTimelineAnnotation("Interrupted exception getting row lock");
        }
        Thread.currentThread().interrupt();
        throw iie;
    } finally {
        // On failure, clean up the counts just in case this was the thing keeping the context alive.
        if (!success && rowLockContext != null) rowLockContext.cleanUp();
        if (traceScope != null) {
            traceScope.close();
        }
    }
}
 
Example 12
Source File: Tracing.java    From phoenix with Apache License 2.0 3 votes vote down vote up
/**
 * Wrap the callable in a TraceCallable, if tracing.
 * @param callable to call
 * @param description description of the operation being run. If <tt>null</tt> uses the current
 *            thread name
 * @return The callable provided, wrapped if tracing, 'callable' if not.
 */
public static <V> Callable<V> wrap(Callable<V> callable, String description) {
    if (Trace.isTracing()) {
        return new TraceCallable<V>(Trace.currentSpan(), callable, description);
    }
    return callable;
}
 
Example 13
Source File: Tracing.java    From phoenix with Apache License 2.0 3 votes vote down vote up
/**
 * Wrap the callable in a TraceCallable, if tracing.
 * @param callable to call
 * @param description description of the operation being run. If <tt>null</tt> uses the current
 *            thread name
 * @return The callable provided, wrapped if tracing, 'callable' if not.
 */
public static <V> Callable<V> wrap(Callable<V> callable, String description) {
    if (Trace.isTracing()) {
        return new TraceCallable<V>(Trace.currentSpan(), callable, description);
    }
    return callable;
}
 
Example 14
Source File: Tracing.java    From phoenix with Apache License 2.0 2 votes vote down vote up
/**
 * Check whether tracing is generally enabled.
 * @return true If tracing is enabled, false otherwise
 */
public static boolean isTracing() {
    return Trace.isTracing();
}