Search in sources :

Example 6 with TraceScope

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

the class RecoverableZooKeeper method getAcl.

/**
   * getAcl is an idempotent operation. Retry before throwing exception
   * @return list of ACLs
   */
public List<ACL> getAcl(String path, Stat stat) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.getAcl");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                return checkZk().getACL(path, stat);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "getAcl");
                        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 7 with TraceScope

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

the class RecoverableZooKeeper method exists.

/**
   * exists is an idempotent operation. Retry before throwing exception
   * @return A Stat instance
   */
public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.exists");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                return checkZk().exists(path, watch);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "exists");
                        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 8 with TraceScope

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

the class RecoverableZooKeeper method setData.

/**
   * setData is NOT an idempotent operation. Retry may cause BadVersion Exception
   * Adding an identifier field into the data to check whether
   * badversion is caused by the result of previous correctly setData
   * @return Stat instance
   */
public Stat setData(String path, byte[] data, int version) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.setData");
        RetryCounter retryCounter = retryCounterFactory.create();
        byte[] newData = appendMetaData(data);
        boolean isRetry = false;
        while (true) {
            try {
                return checkZk().setData(path, newData, version);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "setData");
                        break;
                    case BADVERSION:
                        if (isRetry) {
                            // try to verify whether the previous setData success or not
                            try {
                                Stat stat = new Stat();
                                byte[] revData = checkZk().getData(path, false, stat);
                                if (Bytes.compareTo(revData, newData) == 0) {
                                    // the bad version is caused by previous successful setData
                                    return stat;
                                }
                            } catch (KeeperException keeperException) {
                                // the ZK is not reliable at this moment. just throwing exception
                                throw keeperException;
                            }
                        }
                    // throw other exceptions and verified bad version exceptions
                    default:
                        throw e;
                }
            }
            retryCounter.sleepUntilNextRetry();
            isRetry = true;
        }
    } finally {
        if (traceScope != null)
            traceScope.close();
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) TraceScope(org.apache.htrace.TraceScope) KeeperException(org.apache.zookeeper.KeeperException)

Example 9 with TraceScope

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

the class RecoverableZooKeeper method getChildren.

/**
   * getChildren is an idempotent operation. Retry before throwing exception
   * @return List of children znodes
   */
public List<String> getChildren(String path, boolean watch) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.getChildren");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                return checkZk().getChildren(path, watch);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "getChildren");
                        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 10 with TraceScope

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

the class RecoverableZooKeeper method getChildren.

/**
   * getChildren is an idempotent operation. Retry before throwing exception
   * @return List of children znodes
   */
public List<String> getChildren(String path, Watcher watcher) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.getChildren");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                return checkZk().getChildren(path, watcher);
            } catch (KeeperException e) {
                switch(e.code()) {
                    case CONNECTIONLOSS:
                    case OPERATIONTIMEOUT:
                        retryOrThrow(retryCounter, e, "getChildren");
                        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)

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