Search in sources :

Example 21 with TraceScope

use of org.apache.htrace.TraceScope in project phoenix by apache.

the class Tracing method startNewSpan.

/**
     * Start a span with the currently configured sampling frequency. Creates a new 'current' span
     * on this thread - the previous 'current' span will be replaced with this newly created span.
     * <p>
     * Hands back the direct span as you shouldn't be detaching the span - use {@link TraceRunnable}
     * instead to detach a span from this operation.
     * @param connection from which to read parameters
     * @param string description of the span to start
     * @return the underlying span.
     */
public static TraceScope startNewSpan(PhoenixConnection connection, String string) {
    Sampler<?> sampler = connection.getSampler();
    TraceScope scope = Trace.startSpan(string, sampler);
    addCustomAnnotationsToSpan(scope.getSpan(), connection);
    return scope;
}
Also used : TraceScope(org.apache.htrace.TraceScope)

Example 22 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class RecoverableZooKeeper method getData.

/**
   * getData is an idemnpotent operation. Retry before throwing exception
   * @return Data
   */
public byte[] getData(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.getData");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                byte[] revData = checkZk().getData(path, watch, stat);
                return removeMetaData(revData);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "getData");
                        break;
                    default:
                        throw e;
                }
            }
            retryCounter.sleepUntilNextRetry();
        }
    } finally {
        if (traceScope != null)
            traceScope.close();
    }
}
Also used : RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) TraceScope(org.apache.htrace.TraceScope) KeeperException(org.apache.zookeeper.KeeperException)

Example 23 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class RecoverableZooKeeper method delete.

/**
   * delete is an idempotent operation. Retry before throwing exception.
   * This function will not throw NoNodeException if the path does not
   * exist.
   */
public void delete(String path, int version) throws InterruptedException, KeeperException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.delete");
        RetryCounter retryCounter = retryCounterFactory.create();
        // False for first attempt, true for all retries.
        boolean isRetry = false;
        while (true) {
            try {
                checkZk().delete(path, version);
                return;
            } catch (KeeperException e) {
                switch(e.code()) {
                    case NONODE:
                        if (isRetry) {
                            LOG.debug("Node " + path + " already deleted. Assuming a " + "previous attempt succeeded.");
                            return;
                        }
                        LOG.debug("Node " + path + " already deleted, retry=" + isRetry);
                        throw e;
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "delete");
                        break;
                    default:
                        throw e;
                }
            }
            retryCounter.sleepUntilNextRetry();
            isRetry = true;
        }
    } finally {
        if (traceScope != null)
            traceScope.close();
    }
}
Also used : RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) TraceScope(org.apache.htrace.TraceScope) KeeperException(org.apache.zookeeper.KeeperException)

Example 24 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class RecoverableZooKeeper method setAcl.

/**
   * setAcl is an idempotent operation. Retry before throwing exception
   * @return list of ACLs
   */
public Stat setAcl(String path, List<ACL> acls, int version) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.setAcl");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                return checkZk().setACL(path, acls, version);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "setAcl");
                        break;
                    default:
                        throw e;
                }
            }
            retryCounter.sleepUntilNextRetry();
        }
    } finally {
        if (traceScope != null)
            traceScope.close();
    }
}
Also used : RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) TraceScope(org.apache.htrace.TraceScope) KeeperException(org.apache.zookeeper.KeeperException)

Example 25 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class RecoverableZooKeeper method multi.

/**
   * Run multiple operations in a transactional manner. Retry before throwing exception
   */
public List<OpResult> multi(Iterable<Op> ops) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.multi");
        RetryCounter retryCounter = retryCounterFactory.create();
        Iterable<Op> multiOps = prepareZKMulti(ops);
        while (true) {
            try {
                return checkZk().multi(multiOps);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "multi");
                        break;
                    default:
                        throw e;
                }
            }
            retryCounter.sleepUntilNextRetry();
        }
    } finally {
        if (traceScope != null)
            traceScope.close();
    }
}
Also used : Op(org.apache.zookeeper.Op) RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) TraceScope(org.apache.htrace.TraceScope) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

TraceScope (org.apache.htrace.TraceScope)38 RetryCounter (org.apache.hadoop.hbase.util.RetryCounter)11 KeeperException (org.apache.zookeeper.KeeperException)11 IOException (java.io.IOException)9 Span (org.apache.htrace.Span)7 Pair (org.apache.hadoop.hbase.util.Pair)4 InterruptedIOException (java.io.InterruptedIOException)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 Mutation (org.apache.hadoop.hbase.client.Mutation)3 Table (org.apache.hadoop.hbase.client.Table)3 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Path (org.apache.hadoop.fs.Path)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)2 ResultIterator (org.apache.phoenix.iterate.ResultIterator)2 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)2