Search in sources :

Example 1 with HBaseSnapshotException

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

the class SnapshotManager method restoreSnapshot.

/**
   * Restore the specified snapshot.
   * The restore will fail if the destination table has a snapshot or restore in progress.
   *
   * @param snapshot Snapshot Descriptor
   * @param hTableDescriptor Table Descriptor
   * @param nonceKey unique identifier to prevent duplicated RPC
   * @return procId the ID of the restore snapshot procedure
   */
private synchronized long restoreSnapshot(final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor, final NonceKey nonceKey) throws HBaseSnapshotException {
    final 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 RestoreSnapshotProcedure(master.getMasterProcedureExecutor().getEnvironment(), hTableDescriptor, snapshot), nonceKey);
        this.restoreTableToProcIdMap.put(tableName, procId);
        return procId;
    } catch (Exception e) {
        String msg = "Couldn't restore 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) RestoreSnapshotProcedure(org.apache.hadoop.hbase.master.procedure.RestoreSnapshotProcedure) 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 2 with HBaseSnapshotException

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

the class SnapshotManager method deleteSnapshot.

/**
 * Delete the specified snapshot
 * @param snapshot
 * @throws SnapshotDoesNotExistException If the specified snapshot does not exist.
 * @throws IOException For filesystem IOExceptions
 */
public void deleteSnapshot(SnapshotDescription snapshot) throws IOException {
    // check to see if it is completed
    if (!isSnapshotCompleted(snapshot)) {
        throw new SnapshotDoesNotExistException(ProtobufUtil.createSnapshotDesc(snapshot));
    }
    String snapshotName = snapshot.getName();
    // first create the snapshot description and check to see if it exists
    FileSystem fs = master.getMasterFileSystem().getFileSystem();
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
    // Get snapshot info from file system. The one passed as parameter is a "fake" snapshotInfo with
    // just the "name" and it does not contains the "real" snapshot information
    snapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);
    // call coproc pre hook
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    org.apache.hadoop.hbase.client.SnapshotDescription snapshotPOJO = null;
    if (cpHost != null) {
        snapshotPOJO = ProtobufUtil.createSnapshotDesc(snapshot);
        cpHost.preDeleteSnapshot(snapshotPOJO);
    }
    LOG.debug("Deleting snapshot: " + snapshotName);
    // delete the existing snapshot
    if (!fs.delete(snapshotDir, true)) {
        throw new HBaseSnapshotException("Failed to delete snapshot directory: " + snapshotDir);
    }
    // call coproc post hook
    if (cpHost != null) {
        cpHost.postDeleteSnapshot(snapshotPOJO);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) SnapshotDoesNotExistException(org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)

Example 3 with HBaseSnapshotException

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

Example 4 with HBaseSnapshotException

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

the class SnapshotManager method prepareToTakeSnapshot.

/**
 * Check to make sure that we are OK to run the passed snapshot. Checks to make sure that we
 * aren't already running a snapshot or restore on the requested table.
 * @param snapshot description of the snapshot we want to start
 * @throws HBaseSnapshotException if the filesystem could not be prepared to start the snapshot
 */
private synchronized void prepareToTakeSnapshot(SnapshotDescription snapshot) throws HBaseSnapshotException {
    Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir, master.getConfiguration());
    TableName snapshotTable = TableName.valueOf(snapshot.getTable());
    // make sure we aren't already running a snapshot
    if (isTakingSnapshot(snapshot)) {
        SnapshotSentinel handler = this.snapshotHandlers.get(snapshotTable);
        throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already running another snapshot " + (handler != null ? ("on the same table " + ClientSnapshotDescriptionUtils.toString(handler.getSnapshot())) : "with the same name"), ProtobufUtil.createSnapshotDesc(snapshot));
    }
    // make sure we aren't running a restore on the same table
    if (isRestoringTable(snapshotTable)) {
        throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already have a restore in progress on the same snapshot.");
    }
    try {
        FileSystem workingDirFS = workingDir.getFileSystem(master.getConfiguration());
        // delete the working directory, since we aren't running the snapshot. Likely leftovers
        // from a failed attempt.
        workingDirFS.delete(workingDir, true);
        // recreate the working directory for the snapshot
        if (!workingDirFS.mkdirs(workingDir)) {
            throw new SnapshotCreationException("Couldn't create working directory (" + workingDir + ") for snapshot", ProtobufUtil.createSnapshotDesc(snapshot));
        }
    } catch (HBaseSnapshotException e) {
        throw e;
    } catch (IOException e) {
        throw new SnapshotCreationException("Exception while checking to see if snapshot could be started.", e, ProtobufUtil.createSnapshotDesc(snapshot));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) SnapshotSentinel(org.apache.hadoop.hbase.master.SnapshotSentinel) SnapshotCreationException(org.apache.hadoop.hbase.snapshot.SnapshotCreationException) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) IOException(java.io.IOException)

Example 5 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)

Aggregations

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