Search in sources :

Example 16 with ForeignException

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

the class TestProcedure method testBarrieredErrorPropagation.

@Test
public void testBarrieredErrorPropagation() throws Exception {
    List<String> members = new ArrayList<>();
    members.add("member");
    LatchedProcedure proc = new LatchedProcedure(coord, new ForeignExceptionDispatcher(), 100, Integer.MAX_VALUE, "op", null, members);
    final LatchedProcedure procspy = spy(proc);
    // start the barrier procedure
    Thread t = new Thread() {

        @Override
        public void run() {
            procspy.call();
        }
    };
    t.start();
    // now test that we can put an error in before the commit phase runs
    procspy.startedAcquireBarrier.await();
    ForeignException cause = new ForeignException("SRC", "External Exception");
    procspy.receive(cause);
    procspy.barrierAcquiredByMember(members.get(0));
    t.join();
    // verify state of all the object
    verify(procspy).sendGlobalBarrierStart();
    verify(procspy).sendGlobalBarrierComplete();
    verify(procspy, never()).sendGlobalBarrierReached();
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) Test(org.junit.Test)

Example 17 with ForeignException

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

the class TestProcedure method testErrorPropagation.

@Test
public void testErrorPropagation() throws Exception {
    List<String> members = new ArrayList<>();
    members.add("member");
    Procedure proc = new Procedure(coord, new ForeignExceptionDispatcher(), 100, Integer.MAX_VALUE, "op", null, members);
    final Procedure procspy = spy(proc);
    ForeignException cause = new ForeignException("SRC", "External Exception");
    proc.receive(cause);
    // start the barrier procedure
    Thread t = new Thread() {

        @Override
        public void run() {
            procspy.call();
        }
    };
    t.start();
    t.join();
    verify(procspy, never()).sendGlobalBarrierStart();
    verify(procspy, never()).sendGlobalBarrierReached();
    verify(procspy).sendGlobalBarrierComplete();
}
Also used : ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ForeignExceptionDispatcher(org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher) Test(org.junit.Test)

Example 18 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<HRegionInfo> createFilesystemLayout(final MasterProcedureEnv env, final HTableDescriptor hTableDescriptor, final List<HRegionInfo> newRegions) throws IOException {
    return createFsLayout(env, hTableDescriptor, newRegions, new CreateHdfsRegions() {

        @Override
        public List<HRegionInfo> createHdfsRegions(final MasterProcedureEnv env, final Path tableRootDir, final TableName tableName, final List<HRegionInfo> 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, hTableDescriptor, 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) 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) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) 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 19 with ForeignException

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

the class EnabledTableSnapshotHandler method snapshotRegions.

// TODO consider switching over to using regionnames, rather than server names. This would allow
// regions to migrate during a snapshot, and then be involved when they are ready. Still want to
// enforce a snapshot time constraints, but lets us be potentially a bit more robust.
/**
   * This method kicks off a snapshot procedure.  Other than that it hangs around for various
   * phases to complete.
   */
@Override
protected void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regions) throws HBaseSnapshotException, IOException {
    Set<String> regionServers = new HashSet<>(regions.size());
    for (Pair<HRegionInfo, ServerName> region : regions) {
        if (region != null && region.getFirst() != null && region.getSecond() != null) {
            HRegionInfo hri = region.getFirst();
            if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent()))
                continue;
            regionServers.add(region.getSecond().toString());
        }
    }
    // start the snapshot on the RS
    Procedure proc = coordinator.startProcedure(this.monitor, this.snapshot.getName(), this.snapshot.toByteArray(), Lists.newArrayList(regionServers));
    if (proc == null) {
        String msg = "Failed to submit distributed procedure for snapshot '" + snapshot.getName() + "'";
        LOG.error(msg);
        throw new HBaseSnapshotException(msg);
    }
    try {
        // wait for the snapshot to complete.  A timer thread is kicked off that should cancel this
        // if it takes too long.
        proc.waitForCompleted();
        LOG.info("Done waiting - online snapshot for " + this.snapshot.getName());
        // Take the offline regions as disabled
        for (Pair<HRegionInfo, ServerName> region : regions) {
            HRegionInfo regionInfo = region.getFirst();
            if (regionInfo.isOffline() && (regionInfo.isSplit() || regionInfo.isSplitParent())) {
                LOG.info("Take disabled snapshot of offline region=" + regionInfo);
                snapshotDisabledRegion(regionInfo);
            }
        }
        // handle the mob files if any.
        boolean mobEnabled = MobUtils.hasMobColumns(htd);
        if (mobEnabled) {
            LOG.info("Taking snapshot for mob files in table " + htd.getTableName());
            // snapshot the mob files as a offline region.
            HRegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(htd.getTableName());
            snapshotMobRegion(mobRegionInfo);
        }
    } catch (InterruptedException e) {
        ForeignException ee = new ForeignException("Interrupted while waiting for snapshot to finish", e);
        monitor.receive(ee);
        Thread.currentThread().interrupt();
    } catch (ForeignException e) {
        monitor.receive(e);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) Procedure(org.apache.hadoop.hbase.procedure.Procedure) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) HashSet(java.util.HashSet)

Example 20 with ForeignException

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

the class EnabledTableSnapshotHandler method snapshotRegions.

// TODO consider switching over to using regionnames, rather than server names. This would allow
// regions to migrate during a snapshot, and then be involved when they are ready. Still want to
// enforce a snapshot time constraints, but lets us be potentially a bit more robust.
/**
 * This method kicks off a snapshot procedure.  Other than that it hangs around for various
 * phases to complete.
 */
@Override
protected void snapshotRegions(List<Pair<RegionInfo, ServerName>> regions) throws IOException {
    Set<String> regionServers = new HashSet<>(regions.size());
    for (Pair<RegionInfo, ServerName> region : regions) {
        if (region != null && region.getFirst() != null && region.getSecond() != null) {
            RegionInfo hri = region.getFirst();
            if (hri.isOffline() && (hri.isSplit() || hri.isSplitParent()))
                continue;
            regionServers.add(region.getSecond().toString());
        }
    }
    // start the snapshot on the RS
    Procedure proc = coordinator.startProcedure(this.monitor, this.snapshot.getName(), this.snapshot.toByteArray(), Lists.newArrayList(regionServers));
    if (proc == null) {
        String msg = "Failed to submit distributed procedure for snapshot '" + snapshot.getName() + "'";
        LOG.error(msg);
        throw new HBaseSnapshotException(msg);
    }
    try {
        // wait for the snapshot to complete.  A timer thread is kicked off that should cancel this
        // if it takes too long.
        proc.waitForCompleted();
        LOG.info("Done waiting - online snapshot for " + this.snapshot.getName());
        // Take the offline regions as disabled
        for (Pair<RegionInfo, ServerName> region : regions) {
            RegionInfo regionInfo = region.getFirst();
            if (regionInfo.isOffline() && (regionInfo.isSplit() || regionInfo.isSplitParent()) && RegionReplicaUtil.isDefaultReplica(regionInfo)) {
                LOG.info("Take disabled snapshot of offline region=" + regionInfo);
                snapshotDisabledRegion(regionInfo);
            }
        }
        // handle the mob files if any.
        boolean mobEnabled = MobUtils.hasMobColumns(htd);
        if (mobEnabled) {
            LOG.info("Taking snapshot for mob files in table " + htd.getTableName());
            // snapshot the mob files as a offline region.
            RegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(htd.getTableName());
            snapshotMobRegion(mobRegionInfo);
        }
    } catch (InterruptedException e) {
        ForeignException ee = new ForeignException("Interrupted while waiting for snapshot to finish", e);
        monitor.receive(ee);
        Thread.currentThread().interrupt();
    } catch (ForeignException e) {
        monitor.receive(e);
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) Procedure(org.apache.hadoop.hbase.procedure.Procedure) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HashSet(java.util.HashSet)

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