Search in sources :

Example 1 with SnapshotSentinel

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

use of org.apache.hadoop.hbase.master.SnapshotSentinel 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 {
    FileSystem fs = master.getMasterFileSystem().getFileSystem();
    Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir);
    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 {
        // delete the working directory, since we aren't running the snapshot. Likely leftovers
        // from a failed attempt.
        fs.delete(workingDir, true);
        // recreate the working directory for the snapshot
        if (!fs.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) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) SnapshotSentinel(org.apache.hadoop.hbase.master.SnapshotSentinel) SnapshotCreationException(org.apache.hadoop.hbase.snapshot.SnapshotCreationException) HBaseSnapshotException(org.apache.hadoop.hbase.snapshot.HBaseSnapshotException) IOException(java.io.IOException)

Example 3 with SnapshotSentinel

use of org.apache.hadoop.hbase.master.SnapshotSentinel in project hbase by apache.

the class SnapshotManager method removeSentinelIfFinished.

/**
   * Return the handler if it is currently live and has the same snapshot target name.
   * The handler is removed from the sentinels map if completed.
   * @param sentinels live handlers
   * @param snapshot snapshot description
   * @return null if doesn't match, else a live handler.
   */
private synchronized SnapshotSentinel removeSentinelIfFinished(final Map<TableName, SnapshotSentinel> sentinels, final SnapshotDescription snapshot) {
    if (!snapshot.hasTable()) {
        return null;
    }
    TableName snapshotTable = TableName.valueOf(snapshot.getTable());
    SnapshotSentinel h = sentinels.get(snapshotTable);
    if (h == null) {
        return null;
    }
    if (!h.getSnapshot().getName().equals(snapshot.getName())) {
        // specified snapshot is to the one currently running
        return null;
    }
    // Remove from the "in-progress" list once completed
    if (h.isFinished()) {
        sentinels.remove(snapshotTable);
    }
    return h;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SnapshotSentinel(org.apache.hadoop.hbase.master.SnapshotSentinel)

Example 4 with SnapshotSentinel

use of org.apache.hadoop.hbase.master.SnapshotSentinel in project hbase by apache.

the class SnapshotManager method isTakingSnapshot.

/**
   * Check to see if there is a snapshot in progress with the same name or on the same table.
   * Currently we have a limitation only allowing a single snapshot per table at a time. Also we
   * don't allow snapshot with the same name.
   * @param snapshot description of the snapshot being checked.
   * @return <tt>true</tt> if there is a snapshot in progress with the same name or on the same
   *         table.
   */
synchronized boolean isTakingSnapshot(final SnapshotDescription snapshot) {
    TableName snapshotTable = TableName.valueOf(snapshot.getTable());
    if (isTakingSnapshot(snapshotTable)) {
        return true;
    }
    Iterator<Map.Entry<TableName, SnapshotSentinel>> it = this.snapshotHandlers.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<TableName, SnapshotSentinel> entry = it.next();
        SnapshotSentinel sentinel = entry.getValue();
        if (snapshot.getName().equals(sentinel.getSnapshot().getName()) && !sentinel.isFinished()) {
            return true;
        }
    }
    return false;
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SnapshotSentinel(org.apache.hadoop.hbase.master.SnapshotSentinel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with SnapshotSentinel

use of org.apache.hadoop.hbase.master.SnapshotSentinel in project hbase by apache.

the class SnapshotManager method cleanupSentinels.

/**
   * Remove the sentinels that are marked as finished and the completion time
   * has exceeded the removal timeout.
   * @param sentinels map of sentinels to clean
   */
private synchronized void cleanupSentinels(final Map<TableName, SnapshotSentinel> sentinels) {
    long currentTime = EnvironmentEdgeManager.currentTime();
    Iterator<Map.Entry<TableName, SnapshotSentinel>> it = sentinels.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<TableName, SnapshotSentinel> entry = it.next();
        SnapshotSentinel sentinel = entry.getValue();
        if (sentinel.isFinished() && (currentTime - sentinel.getCompletionTimestamp()) > SNAPSHOT_SENTINELS_CLEANUP_TIMEOUT) {
            it.remove();
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SnapshotSentinel(org.apache.hadoop.hbase.master.SnapshotSentinel) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SnapshotSentinel (org.apache.hadoop.hbase.master.SnapshotSentinel)5 TableName (org.apache.hadoop.hbase.TableName)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HBaseSnapshotException (org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)2 IOException (java.io.IOException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)1 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)1 CloneSnapshotProcedure (org.apache.hadoop.hbase.master.procedure.CloneSnapshotProcedure)1 RestoreSnapshotProcedure (org.apache.hadoop.hbase.master.procedure.RestoreSnapshotProcedure)1 Procedure (org.apache.hadoop.hbase.procedure.Procedure)1 SnapshotCreationException (org.apache.hadoop.hbase.snapshot.SnapshotCreationException)1 UnknownSnapshotException (org.apache.hadoop.hbase.snapshot.UnknownSnapshotException)1