Search in sources :

Example 6 with HBaseSnapshotException

use of org.apache.hadoop.hbase.snapshot.HBaseSnapshotException in project hbase by apache.

the class SnapshotManager method cloneSnapshot.

/**
   * Clone the specified snapshot into a new table.
   * The operation will fail if the destination table has a snapshot or restore in progress.
   *
   * @param snapshot Snapshot Descriptor
   * @param hTableDescriptor Table Descriptor of the table to create
   * @param nonceKey unique identifier to prevent duplicated RPC
   * @return procId the ID of the clone snapshot procedure
   */
synchronized long cloneSnapshot(final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor, final NonceKey nonceKey) throws HBaseSnapshotException {
    TableName tableName = hTableDescriptor.getTableName();
    // make sure we aren't running a snapshot on the same table
    if (isTakingSnapshot(tableName)) {
        throw new RestoreSnapshotException("Snapshot in progress on the restore table=" + tableName);
    }
    // make sure we aren't running a restore on the same table
    if (isRestoringTable(tableName)) {
        throw new RestoreSnapshotException("Restore already in progress on the table=" + tableName);
    }
    try {
        long procId = master.getMasterProcedureExecutor().submitProcedure(new CloneSnapshotProcedure(master.getMasterProcedureExecutor().getEnvironment(), hTableDescriptor, snapshot), nonceKey);
        this.restoreTableToProcIdMap.put(tableName, procId);
        return procId;
    } catch (Exception e) {
        String msg = "Couldn't clone the snapshot=" + ClientSnapshotDescriptionUtils.toString(snapshot) + " on table=" + tableName;
        LOG.error(msg, e);
        throw new RestoreSnapshotException(msg, e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) CloneSnapshotProcedure(org.apache.hadoop.hbase.master.procedure.CloneSnapshotProcedure) SnapshotExistsException(org.apache.hadoop.hbase.snapshot.SnapshotExistsException) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) TablePartiallyOpenException(org.apache.hadoop.hbase.snapshot.TablePartiallyOpenException) SnapshotCreationException(org.apache.hadoop.hbase.snapshot.SnapshotCreationException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownSnapshotException(org.apache.hadoop.hbase.snapshot.UnknownSnapshotException) SnapshotDoesNotExistException(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)

Example 7 with HBaseSnapshotException

use of org.apache.hadoop.hbase.snapshot.HBaseSnapshotException 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)

Aggregations

HBaseSnapshotException (org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)7 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)5 IOException (java.io.IOException)4 SnapshotCreationException (org.apache.hadoop.hbase.snapshot.SnapshotCreationException)4 SnapshotDoesNotExistException (org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)4 UnknownSnapshotException (org.apache.hadoop.hbase.snapshot.UnknownSnapshotException)4 FileNotFoundException (java.io.FileNotFoundException)3 Path (org.apache.hadoop.fs.Path)3 TableName (org.apache.hadoop.hbase.TableName)3 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)3 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)3 SnapshotExistsException (org.apache.hadoop.hbase.snapshot.SnapshotExistsException)3 TablePartiallyOpenException (org.apache.hadoop.hbase.snapshot.TablePartiallyOpenException)3 KeeperException (org.apache.zookeeper.KeeperException)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)2 SnapshotSentinel (org.apache.hadoop.hbase.master.SnapshotSentinel)2 CloneSnapshotProcedure (org.apache.hadoop.hbase.master.procedure.CloneSnapshotProcedure)2 RestoreSnapshotProcedure (org.apache.hadoop.hbase.master.procedure.RestoreSnapshotProcedure)2 Procedure (org.apache.hadoop.hbase.procedure.Procedure)2