Search in sources :

Example 26 with KeeperException

use of org.apache.zookeeper.KeeperException in project hbase by apache.

the class ZKProcedureCoordinator method sendGlobalBarrierReached.

@Override
public void sendGlobalBarrierReached(Procedure proc, List<String> nodeNames) throws IOException {
    String procName = proc.getName();
    String reachedNode = zkProc.getReachedBarrierNode(procName);
    LOG.debug("Creating reached barrier zk node:" + reachedNode);
    try {
        // create the reached znode and watch for the reached znodes
        ZKUtil.createWithParents(zkProc.getWatcher(), reachedNode);
        // loop through all the children of the acquire phase and watch for them
        for (String node : nodeNames) {
            String znode = ZKUtil.joinZNode(reachedNode, node);
            if (ZKUtil.watchAndCheckExists(zkProc.getWatcher(), znode)) {
                byte[] dataFromMember = ZKUtil.getData(zkProc.getWatcher(), znode);
                // ProtobufUtil.isPBMagicPrefix will check null
                if (dataFromMember != null && dataFromMember.length > 0) {
                    if (!ProtobufUtil.isPBMagicPrefix(dataFromMember)) {
                        String msg = "Failed to get data from finished node or data is illegally formatted: " + znode;
                        LOG.error(msg);
                        throw new IOException(msg);
                    } else {
                        dataFromMember = Arrays.copyOfRange(dataFromMember, ProtobufUtil.lengthOfPBMagic(), dataFromMember.length);
                        coordinator.memberFinishedBarrier(procName, node, dataFromMember);
                    }
                } else {
                    coordinator.memberFinishedBarrier(procName, node, dataFromMember);
                }
            }
        }
    } catch (KeeperException e) {
        String msg = "Failed while creating reached node:" + reachedNode;
        LOG.error(msg, e);
        throw new IOException(msg, e);
    } catch (InterruptedException e) {
        String msg = "Interrupted while creating reached node:" + reachedNode;
        LOG.error(msg, e);
        throw new InterruptedIOException(msg);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 27 with KeeperException

use of org.apache.zookeeper.KeeperException in project hbase by apache.

the class ZKProcedureCoordinator method abort.

/**
   * Receive a notification and propagate it to the local coordinator
   * @param abortNode full znode path to the failed procedure information
   */
protected void abort(String abortNode) {
    String procName = ZKUtil.getNodeName(abortNode);
    ForeignException ee = null;
    try {
        byte[] data = ZKUtil.getData(zkProc.getWatcher(), abortNode);
        if (data == null || data.length == 0) {
            // ignore
            return;
        } else if (!ProtobufUtil.isPBMagicPrefix(data)) {
            LOG.warn("Got an error notification for op:" + abortNode + " but we can't read the information. Killing the procedure.");
            // we got a remote exception, but we can't describe it
            ee = new ForeignException(coordName, "Data in abort node is illegally formatted.  ignoring content.");
        } else {
            data = Arrays.copyOfRange(data, ProtobufUtil.lengthOfPBMagic(), data.length);
            ee = ForeignException.deserialize(data);
        }
    } catch (IOException e) {
        LOG.warn("Got an error notification for op:" + abortNode + " but we can't read the information. Killing the procedure.");
        // we got a remote exception, but we can't describe it
        ee = new ForeignException(coordName, e);
    } catch (KeeperException e) {
        coordinator.rpcConnectionFailure("Failed to get data for abort node:" + abortNode + zkProc.getAbortZnode(), new IOException(e));
    } catch (InterruptedException e) {
        coordinator.rpcConnectionFailure("Failed to get data for abort node:" + abortNode + zkProc.getAbortZnode(), new IOException(e));
        Thread.currentThread().interrupt();
    }
    coordinator.abortProcedure(procName, ee);
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 28 with KeeperException

use of org.apache.zookeeper.KeeperException in project hbase by apache.

the class ZKProcedureMemberRpcs method abort.

/**
   * Pass along the found abort notification to the listener
   * @param abortZNode full znode path to the failed procedure information
   */
protected void abort(String abortZNode) {
    LOG.debug("Aborting procedure member for znode " + abortZNode);
    String opName = ZKUtil.getNodeName(abortZNode);
    try {
        byte[] data = ZKUtil.getData(zkController.getWatcher(), abortZNode);
        // figure out the data we need to pass
        ForeignException ee;
        try {
            if (data == null || data.length == 0) {
                // ignore
                return;
            } else if (!ProtobufUtil.isPBMagicPrefix(data)) {
                String msg = "Illegally formatted data in abort node for proc " + opName + ".  Killing the procedure.";
                LOG.error(msg);
                // we got a remote exception, but we can't describe it so just return exn from here
                ee = new ForeignException(getMemberName(), new IllegalArgumentException(msg));
            } else {
                data = Arrays.copyOfRange(data, ProtobufUtil.lengthOfPBMagic(), data.length);
                ee = ForeignException.deserialize(data);
            }
        } catch (IOException e) {
            LOG.warn("Got an error notification for op:" + opName + " but we can't read the information. Killing the procedure.");
            // we got a remote exception, but we can't describe it so just return exn from here
            ee = new ForeignException(getMemberName(), e);
        }
        this.member.receiveAbortProcedure(opName, ee);
    } catch (KeeperException e) {
        member.controllerConnectionFailure("Failed to get data for abort znode:" + abortZNode + zkController.getAbortZnode(), e, opName);
    } catch (InterruptedException e) {
        LOG.warn("abort already in progress", e);
        Thread.currentThread().interrupt();
    }
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 29 with KeeperException

use of 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)

Example 30 with KeeperException

use of org.apache.zookeeper.KeeperException in project hbase by apache.

the class ReplicationPeersZKImpl method createPeer.

/**
   * Helper method to connect to a peer
   * @param peerId peer's identifier
   * @return object representing the peer
   * @throws ReplicationException
   */
private ReplicationPeerZKImpl createPeer(String peerId) throws ReplicationException {
    Pair<ReplicationPeerConfig, Configuration> pair = getPeerConf(peerId);
    if (pair == null) {
        return null;
    }
    Configuration peerConf = pair.getSecond();
    ReplicationPeerZKImpl peer = new ReplicationPeerZKImpl(zookeeper, peerConf, peerId, pair.getFirst(), abortable);
    try {
        peer.startStateTracker(this.getPeerStateNode(peerId));
    } catch (KeeperException e) {
        throw new ReplicationException("Error starting the peer state tracker for peerId=" + peerId, e);
    }
    try {
        peer.startPeerConfigTracker(this.getPeerNode(peerId));
    } catch (KeeperException e) {
        throw new ReplicationException("Error starting the peer tableCFs tracker for peerId=" + peerId, e);
    }
    return peer;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CompoundConfiguration(org.apache.hadoop.hbase.CompoundConfiguration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)345 IOException (java.io.IOException)114 Stat (org.apache.zookeeper.data.Stat)79 ZooKeeper (org.apache.zookeeper.ZooKeeper)54 Test (org.junit.Test)37 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)36 ArrayList (java.util.ArrayList)30 SolrException (org.apache.solr.common.SolrException)30 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)24 HashMap (java.util.HashMap)21 WatchedEvent (org.apache.zookeeper.WatchedEvent)20 Watcher (org.apache.zookeeper.Watcher)20 InterruptedIOException (java.io.InterruptedIOException)19 Map (java.util.Map)19 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)17 ServerName (org.apache.hadoop.hbase.ServerName)15 ACL (org.apache.zookeeper.data.ACL)15 List (java.util.List)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 RetryCounter (org.apache.hadoop.hbase.util.RetryCounter)13