Search in sources :

Example 11 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project hbase by apache.

the class RecoverableZooKeeper method getData.

/**
   * getData is an idempotent operation. Retry before throwing exception
   * @return Data
   */
public byte[] getData(String path, Watcher watcher, 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, watcher, 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 12 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException 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, Watcher watcher) throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
        traceScope = Trace.startSpan("RecoverableZookeeper.exists");
        RetryCounter retryCounter = retryCounterFactory.create();
        while (true) {
            try {
                return checkZk().exists(path, watcher);
            } 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 13 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project hbase by apache.

the class ZKUtil method watchAndCheckExists.

//
// Existence checks and watches
//
/**
   * Watch the specified znode for delete/create/change events.  The watcher is
   * set whether or not the node exists.  If the node already exists, the method
   * returns true.  If the node does not exist, the method returns false.
   *
   * @param zkw zk reference
   * @param znode path of node to watch
   * @return true if znode exists, false if does not exist or error
   * @throws KeeperException if unexpected zookeeper exception
   */
public static boolean watchAndCheckExists(ZooKeeperWatcher zkw, String znode) throws KeeperException {
    try {
        Stat s = zkw.getRecoverableZooKeeper().exists(znode, zkw);
        boolean exists = s != null ? true : false;
        if (exists) {
            LOG.debug(zkw.prefix("Set watcher on existing znode=" + znode));
        } else {
            LOG.debug(zkw.prefix("Set watcher on znode that does not yet exist, " + znode));
        }
        return exists;
    } catch (KeeperException e) {
        LOG.warn(zkw.prefix("Unable to set watcher on znode " + znode), e);
        zkw.keeperException(e);
        return false;
    } catch (InterruptedException e) {
        LOG.warn(zkw.prefix("Unable to set watcher on znode " + znode), e);
        zkw.interruptedException(e);
        return false;
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Example 14 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project hbase by apache.

the class DisabledTableSnapshotHandler method snapshotRegions.

// TODO consider parallelizing these operations since they are independent. Right now its just
// easier to keep them serial though
@Override
public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations) throws IOException, KeeperException {
    try {
        // 1. get all the regions hosting this table.
        // extract each pair to separate lists
        Set<HRegionInfo> regions = new HashSet<>();
        for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
            // Don't include non-default regions
            HRegionInfo hri = p.getFirst();
            if (RegionReplicaUtil.isDefaultReplica(hri)) {
                regions.add(hri);
            }
        }
        // handle the mob files if any.
        boolean mobEnabled = MobUtils.hasMobColumns(htd);
        if (mobEnabled) {
            // snapshot the mob files as a offline region.
            HRegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(htd.getTableName());
            regions.add(mobRegionInfo);
        }
        // 2. for each region, write all the info to disk
        String msg = "Starting to write region info and WALs for regions for offline snapshot:" + ClientSnapshotDescriptionUtils.toString(snapshot);
        LOG.info(msg);
        status.setStatus(msg);
        ThreadPoolExecutor exec = SnapshotManifest.createExecutor(conf, "DisabledTableSnapshot");
        try {
            ModifyRegionUtils.editRegions(exec, regions, new ModifyRegionUtils.RegionEditTask() {

                @Override
                public void editRegion(final HRegionInfo regionInfo) throws IOException {
                    snapshotManifest.addRegion(FSUtils.getTableDir(rootDir, snapshotTable), regionInfo);
                }
            });
        } finally {
            exec.shutdown();
        }
    } catch (Exception e) {
        // make sure we capture the exception to propagate back to the client later
        String reason = "Failed snapshot " + ClientSnapshotDescriptionUtils.toString(snapshot) + " due to exception:" + e.getMessage();
        ForeignException ee = new ForeignException(reason, e);
        monitor.receive(ee);
        status.abort("Snapshot of table: " + snapshotTable + " failed because " + e.getMessage());
    } finally {
        LOG.debug("Marking snapshot" + ClientSnapshotDescriptionUtils.toString(snapshot) + " as finished.");
    }
}
Also used : IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ModifyRegionUtils(org.apache.hadoop.hbase.util.ModifyRegionUtils) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) HashSet(java.util.HashSet)

Example 15 with KeeperException

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project hbase by apache.

the class ServerCrashProcedure method verifyAndAssignMetaWithRetries.

/**
   * If hbase:meta is not assigned already, assign.
   * @throws IOException
   */
private void verifyAndAssignMetaWithRetries(final MasterProcedureEnv env) throws IOException {
    MasterServices services = env.getMasterServices();
    int iTimes = services.getConfiguration().getInt(KEY_RETRIES_ON_META, DEFAULT_RETRIES_ON_META);
    // Just reuse same time as we have for short wait on meta. Adding another config is overkill.
    long waitTime = services.getConfiguration().getLong(KEY_SHORT_WAIT_ON_META, DEFAULT_SHORT_WAIT_ON_META);
    int iFlag = 0;
    while (true) {
        try {
            verifyAndAssignMeta(env);
            break;
        } catch (KeeperException e) {
            services.abort("In server shutdown processing, assigning meta", e);
            throw new IOException("Aborting", e);
        } catch (Exception e) {
            if (iFlag >= iTimes) {
                services.abort("verifyAndAssignMeta failed after" + iTimes + " retries, aborting", e);
                throw new IOException("Aborting", e);
            }
            try {
                Thread.sleep(waitTime);
            } catch (InterruptedException e1) {
                LOG.warn("Interrupted when is the thread sleep", e1);
                Thread.currentThread().interrupt();
                throw (InterruptedIOException) new InterruptedIOException().initCause(e1);
            }
            iFlag++;
        }
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) MasterServices(org.apache.hadoop.hbase.master.MasterServices) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException) InterruptedIOException(java.io.InterruptedIOException) ProcedureYieldException(org.apache.hadoop.hbase.procedure2.ProcedureYieldException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)608 IOException (java.io.IOException)206 Stat (org.apache.zookeeper.data.Stat)131 ZooKeeper (org.apache.zookeeper.ZooKeeper)89 ArrayList (java.util.ArrayList)55 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)45 Watcher (org.apache.zookeeper.Watcher)43 WatchedEvent (org.apache.zookeeper.WatchedEvent)42 Test (org.junit.jupiter.api.Test)38 HashMap (java.util.HashMap)33 List (java.util.List)32 CountDownLatch (java.util.concurrent.CountDownLatch)32 SolrException (org.apache.solr.common.SolrException)30 Test (org.junit.Test)29 ACL (org.apache.zookeeper.data.ACL)27 Map (java.util.Map)26 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)25 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)24 ServerName (org.apache.hadoop.hbase.ServerName)24 OpResult (org.apache.zookeeper.OpResult)21