Search in sources :

Example 6 with ForeignException

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

the class MasterRpcServices method execProcedure.

/**
 * Triggers an asynchronous attempt to run a distributed procedure.
 * {@inheritDoc}
 */
@Override
public ExecProcedureResponse execProcedure(RpcController controller, ExecProcedureRequest request) throws ServiceException {
    try {
        server.checkInitialized();
        ProcedureDescription desc = request.getProcedure();
        MasterProcedureManager mpm = server.getMasterProcedureManagerHost().getProcedureManager(desc.getSignature());
        if (mpm == null) {
            throw new ServiceException(new DoNotRetryIOException("The procedure is not registered: " + desc.getSignature()));
        }
        LOG.info(server.getClientIdAuditPrefix() + " procedure request for: " + desc.getSignature());
        mpm.checkPermissions(desc, getAccessChecker(), RpcServer.getRequestUser().orElse(null));
        mpm.execProcedure(desc);
        // send back the max amount of time the client should wait for the procedure
        // to complete
        long waitTime = SnapshotDescriptionUtils.DEFAULT_MAX_WAIT_TIME;
        return ExecProcedureResponse.newBuilder().setExpectedTimeout(waitTime).build();
    } catch (ForeignException e) {
        throw new ServiceException(e.getCause());
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ProcedureDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription) MasterProcedureManager(org.apache.hadoop.hbase.procedure.MasterProcedureManager) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 7 with ForeignException

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

the class MasterRpcServices method isProcedureDone.

/**
 * Checks if the specified procedure is done.
 * @return true if the procedure is done, false if the procedure is in the process of completing
 * @throws ServiceException if invalid procedure or failed procedure with progress failure reason.
 */
@Override
public IsProcedureDoneResponse isProcedureDone(RpcController controller, IsProcedureDoneRequest request) throws ServiceException {
    try {
        server.checkInitialized();
        ProcedureDescription desc = request.getProcedure();
        MasterProcedureManager mpm = server.getMasterProcedureManagerHost().getProcedureManager(desc.getSignature());
        if (mpm == null) {
            throw new ServiceException("The procedure is not registered: " + desc.getSignature());
        }
        LOG.debug("Checking to see if procedure from request:" + desc.getSignature() + " is done");
        IsProcedureDoneResponse.Builder builder = IsProcedureDoneResponse.newBuilder();
        boolean done = mpm.isProcedureDone(desc);
        builder.setDone(done);
        return builder.build();
    } catch (ForeignException e) {
        throw new ServiceException(e.getCause());
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ProcedureDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription) IsProcedureDoneResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsProcedureDoneResponse) MasterProcedureManager(org.apache.hadoop.hbase.procedure.MasterProcedureManager) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 8 with ForeignException

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

the class CloneSnapshotProcedure method createFilesystemLayout.

/**
 * Create regions in file system.
 * @param env MasterProcedureEnv
 * @throws IOException
 */
private List<RegionInfo> createFilesystemLayout(final MasterProcedureEnv env, final TableDescriptor tableDescriptor, final List<RegionInfo> newRegions) throws IOException {
    return createFsLayout(env, tableDescriptor, newRegions, new CreateHdfsRegions() {

        @Override
        public List<RegionInfo> createHdfsRegions(final MasterProcedureEnv env, final Path tableRootDir, final TableName tableName, final List<RegionInfo> newRegions) throws IOException {
            final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem();
            final FileSystem fs = mfs.getFileSystem();
            final Path rootDir = mfs.getRootDir();
            final Configuration conf = env.getMasterConfiguration();
            final ForeignExceptionDispatcher monitorException = new ForeignExceptionDispatcher();
            getMonitorStatus().setStatus("Clone snapshot - creating regions for table: " + tableName);
            try {
                // 1. Execute the on-disk Clone
                Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
                SnapshotManifest manifest = SnapshotManifest.open(conf, fs, snapshotDir, snapshot);
                RestoreSnapshotHelper restoreHelper = new RestoreSnapshotHelper(conf, fs, manifest, tableDescriptor, tableRootDir, monitorException, monitorStatus);
                RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();
                // Clone operation should not have stuff to restore or remove
                Preconditions.checkArgument(!metaChanges.hasRegionsToRestore(), "A clone should not have regions to restore");
                Preconditions.checkArgument(!metaChanges.hasRegionsToRemove(), "A clone should not have regions to remove");
                // At this point the clone is complete. Next step is enabling the table.
                String msg = "Clone snapshot=" + snapshot.getName() + " on table=" + tableName + " completed!";
                LOG.info(msg);
                monitorStatus.setStatus(msg + " Waiting for table to be enabled...");
                // 2. Let the next step to add the regions to meta
                return metaChanges.getRegionsToAdd();
            } catch (Exception e) {
                String msg = "clone snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) + " failed because " + e.getMessage();
                LOG.error(msg, e);
                IOException rse = new RestoreSnapshotException(msg, e, ProtobufUtil.createSnapshotDesc(snapshot));
                // these handlers aren't futures so we need to register the error here.
                monitorException.receive(new ForeignException("Master CloneSnapshotProcedure", rse));
                throw rse;
            }
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) Configuration(org.apache.hadoop.conf.Configuration) CreateHdfsRegions(org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.CreateHdfsRegions) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) IOException(java.io.IOException) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) TableName(org.apache.hadoop.hbase.TableName) SnapshotManifest(org.apache.hadoop.hbase.snapshot.SnapshotManifest) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) List(java.util.List) RestoreSnapshotHelper(org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper)

Example 9 with ForeignException

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

the class FlushSnapshotSubprocedure method flushSnapshot.

private void flushSnapshot() throws ForeignException {
    if (regions.isEmpty()) {
        // No regions on this RS, we are basically done.
        return;
    }
    monitor.rethrowException();
    // assert that the taskManager is empty.
    if (taskManager.hasTasks()) {
        throw new IllegalStateException("Attempting to take snapshot " + ClientSnapshotDescriptionUtils.toString(snapshot) + " but we currently have outstanding tasks");
    }
    // Add all hfiles already existing in region.
    for (HRegion region : regions) {
        // submit one task per region for parallelize by region.
        taskManager.submitTask(new RegionSnapshotTask(region, snapshot, snapshotSkipFlush, monitor));
        monitor.rethrowException();
    }
    // wait for everything to complete.
    LOG.debug("Flush Snapshot Tasks submitted for " + regions.size() + " regions");
    try {
        taskManager.waitForOutstandingTasks();
    } catch (InterruptedException e) {
        LOG.error("got interrupted exception for " + getMemberName());
        throw new ForeignException(getMemberName(), e);
    }
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException)

Example 10 with ForeignException

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

the class SnapshotManager method isSnapshotDone.

/**
 * Check if the specified snapshot is done
 *
 * @param expected
 * @return true if snapshot is ready to be restored, false if it is still being taken.
 * @throws IOException IOException if error from HDFS or RPC
 * @throws UnknownSnapshotException if snapshot is invalid or does not exist.
 */
public boolean isSnapshotDone(SnapshotDescription expected) throws IOException {
    // check the request to make sure it has a snapshot
    if (expected == null) {
        throw new UnknownSnapshotException("No snapshot name passed in request, can't figure out which snapshot you want to check.");
    }
    String ssString = ClientSnapshotDescriptionUtils.toString(expected);
    // check to see if the sentinel exists,
    // and if the task is complete removes it from the in-progress snapshots map.
    SnapshotSentinel handler = removeSentinelIfFinished(this.snapshotHandlers, expected);
    // stop tracking "abandoned" handlers
    cleanupSentinels();
    if (handler == null) {
        // otherwise raise an exception saying that the snapshot is not running and doesn't exist.
        if (!isSnapshotCompleted(expected)) {
            throw new UnknownSnapshotException("Snapshot " + ssString + " is not currently running or one of the known completed snapshots.");
        }
        // was done, return true;
        return true;
    }
    // pass on any failure we find in the sentinel
    try {
        handler.rethrowExceptionIfFailed();
    } catch (ForeignException e) {
        // Give some procedure info on an exception.
        String status;
        Procedure p = coordinator.getProcedure(expected.getName());
        if (p != null) {
            status = p.getStatus();
        } else {
            status = expected.getName() + " not found in proclist " + coordinator.getProcedureNames();
        }
        throw new HBaseSnapshotException("Snapshot " + ssString + " had an error.  " + status, e, ProtobufUtil.createSnapshotDesc(expected));
    }
    // check to see if we are done
    if (handler.isFinished()) {
        LOG.debug("Snapshot '" + ssString + "' has completed, notifying client.");
        return true;
    } else if (LOG.isDebugEnabled()) {
        LOG.debug("Snapshoting '" + ssString + "' is still in progress!");
    }
    return false;
}
Also used : UnknownSnapshotException(org.apache.hadoop.hbase.snapshot.UnknownSnapshotException) SnapshotSentinel(org.apache.hadoop.hbase.master.SnapshotSentinel) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) RestoreSnapshotProcedure(org.apache.hadoop.hbase.master.procedure.RestoreSnapshotProcedure) CloneSnapshotProcedure(org.apache.hadoop.hbase.master.procedure.CloneSnapshotProcedure) Procedure(org.apache.hadoop.hbase.procedure.Procedure) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)

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