Search in sources :

Example 1 with ForeignException

use of org.apache.hadoop.hbase.errorhandling.ForeignException 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 2 with ForeignException

use of org.apache.hadoop.hbase.errorhandling.ForeignException 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 3 with ForeignException

use of org.apache.hadoop.hbase.errorhandling.ForeignException 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 4 with ForeignException

use of org.apache.hadoop.hbase.errorhandling.ForeignException in project hbase by apache.

the class ZKProcedureCoordinator method start.

/**
 * Start monitoring znodes in ZK - subclass hook to start monitoring znodes they are about.
 * @return true if succeed, false if encountered initialization errors.
 */
@Override
public final boolean start(final ProcedureCoordinator coordinator) {
    if (this.coordinator != null) {
        throw new IllegalStateException("ZKProcedureCoordinator already started and already has listener installed");
    }
    this.coordinator = coordinator;
    try {
        this.zkProc = new ZKProcedureUtil(watcher, procedureType) {

            @Override
            public void nodeCreated(String path) {
                if (!isInProcedurePath(path))
                    return;
                LOG.debug("Node created: " + path);
                logZKTree(this.baseZNode);
                if (isAcquiredPathNode(path)) {
                    // node wasn't present when we created the watch so zk event triggers acquire
                    coordinator.memberAcquiredBarrier(ZKUtil.getNodeName(ZKUtil.getParent(path)), ZKUtil.getNodeName(path));
                } else if (isReachedPathNode(path)) {
                    // node was absent when we created the watch so zk event triggers the finished barrier.
                    // TODO Nothing enforces that acquire and reached znodes from showing up in wrong order.
                    String procName = ZKUtil.getNodeName(ZKUtil.getParent(path));
                    String member = ZKUtil.getNodeName(path);
                    // get the data from the procedure member
                    try {
                        byte[] dataFromMember = ZKUtil.getData(watcher, path);
                        // ProtobufUtil.isPBMagicPrefix will check null
                        if (dataFromMember != null && dataFromMember.length > 0) {
                            if (!ProtobufUtil.isPBMagicPrefix(dataFromMember)) {
                                ForeignException ee = new ForeignException(coordName, "Failed to get data from finished node or data is illegally formatted:" + path);
                                coordinator.abortProcedure(procName, ee);
                            } else {
                                dataFromMember = Arrays.copyOfRange(dataFromMember, ProtobufUtil.lengthOfPBMagic(), dataFromMember.length);
                                LOG.debug("Finished data from procedure '{}' member '{}': {}", procName, member, new String(dataFromMember, StandardCharsets.UTF_8));
                                coordinator.memberFinishedBarrier(procName, member, dataFromMember);
                            }
                        } else {
                            coordinator.memberFinishedBarrier(procName, member, dataFromMember);
                        }
                    } catch (KeeperException e) {
                        ForeignException ee = new ForeignException(coordName, e);
                        coordinator.abortProcedure(procName, ee);
                    } catch (InterruptedException e) {
                        ForeignException ee = new ForeignException(coordName, e);
                        coordinator.abortProcedure(procName, ee);
                    }
                } else if (isAbortPathNode(path)) {
                    abort(path);
                } else {
                    LOG.debug("Ignoring created notification for node:" + path);
                }
            }
        };
        zkProc.clearChildZNodes();
    } catch (KeeperException e) {
        LOG.error("Unable to start the ZK-based Procedure Coordinator rpcs.", e);
        return false;
    }
    LOG.debug("Starting controller for procedure member=" + coordName);
    return true;
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) KeeperException(org.apache.zookeeper.KeeperException)

Example 5 with ForeignException

use of org.apache.hadoop.hbase.errorhandling.ForeignException in project hbase by apache.

the class Subprocedure method cancel.

/**
 * Method to cancel the Subprocedure by injecting an exception from and external source.
 * @param cause
 */
public void cancel(String msg, Throwable cause) {
    LOG.error(msg, cause);
    complete = true;
    if (cause instanceof ForeignException) {
        monitor.receive((ForeignException) cause);
    } else {
        monitor.receive(new ForeignException(getMemberName(), cause));
    }
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException)

Aggregations

ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)29 IOException (java.io.IOException)17 ForeignExceptionDispatcher (org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher)11 ServerName (org.apache.hadoop.hbase.ServerName)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)6 KeeperException (org.apache.zookeeper.KeeperException)6 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)5 Procedure (org.apache.hadoop.hbase.procedure.Procedure)5 RestoreSnapshotHelper (org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper)4 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)4 Test (org.junit.Test)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 Configuration (org.apache.hadoop.conf.Configuration)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 Path (org.apache.hadoop.fs.Path)3 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 TableName (org.apache.hadoop.hbase.TableName)3 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)3