Search in sources :

Example 6 with SnapshotCreationException

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

the class SnapshotManager method takeSnapshotInternal.

private void takeSnapshotInternal(SnapshotDescription snapshot) throws IOException {
    // check to see if we already completed the snapshot
    if (isSnapshotCompleted(snapshot)) {
        throw new SnapshotExistsException("Snapshot '" + snapshot.getName() + "' already stored on the filesystem.", ProtobufUtil.createSnapshotDesc(snapshot));
    }
    LOG.debug("No existing snapshot, attempting snapshot...");
    // stop tracking "abandoned" handlers
    cleanupSentinels();
    // check to see if the table exists
    TableDescriptor desc = null;
    try {
        desc = master.getTableDescriptors().get(TableName.valueOf(snapshot.getTable()));
    } catch (FileNotFoundException e) {
        String msg = "Table:" + snapshot.getTable() + " info doesn't exist!";
        LOG.error(msg);
        throw new SnapshotCreationException(msg, e, ProtobufUtil.createSnapshotDesc(snapshot));
    } catch (IOException e) {
        throw new SnapshotCreationException("Error while geting table description for table " + snapshot.getTable(), e, ProtobufUtil.createSnapshotDesc(snapshot));
    }
    if (desc == null) {
        throw new SnapshotCreationException("Table '" + snapshot.getTable() + "' doesn't exist, can't take snapshot.", ProtobufUtil.createSnapshotDesc(snapshot));
    }
    SnapshotDescription.Builder builder = snapshot.toBuilder();
    // if not specified, set the snapshot format
    if (!snapshot.hasVersion()) {
        builder.setVersion(SnapshotDescriptionUtils.SNAPSHOT_LAYOUT_VERSION);
    }
    RpcServer.getRequestUser().ifPresent(user -> {
        if (AccessChecker.isAuthorizationSupported(master.getConfiguration())) {
            builder.setOwner(user.getShortName());
        }
    });
    snapshot = builder.build();
    // call pre coproc hook
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    org.apache.hadoop.hbase.client.SnapshotDescription snapshotPOJO = null;
    if (cpHost != null) {
        snapshotPOJO = ProtobufUtil.createSnapshotDesc(snapshot);
        cpHost.preSnapshot(snapshotPOJO, desc);
    }
    // if the table is enabled, then have the RS run actually the snapshot work
    TableName snapshotTable = TableName.valueOf(snapshot.getTable());
    if (master.getTableStateManager().isTableState(snapshotTable, TableState.State.ENABLED)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Table enabled, starting distributed snapshots for {}", ClientSnapshotDescriptionUtils.toString(snapshot));
        }
        snapshotEnabledTable(snapshot);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Started snapshot: {}", ClientSnapshotDescriptionUtils.toString(snapshot));
        }
    } else // For disabled table, snapshot is created by the master
    if (master.getTableStateManager().isTableState(snapshotTable, TableState.State.DISABLED)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Table is disabled, running snapshot entirely on master for {}", ClientSnapshotDescriptionUtils.toString(snapshot));
        }
        snapshotDisabledTable(snapshot);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Started snapshot: {}", ClientSnapshotDescriptionUtils.toString(snapshot));
        }
    } else {
        LOG.error("Can't snapshot table '" + snapshot.getTable() + "', isn't open or closed, we don't know what to do!");
        TablePartiallyOpenException tpoe = new TablePartiallyOpenException(snapshot.getTable() + " isn't fully open.");
        throw new SnapshotCreationException("Table is not entirely open or closed", tpoe, ProtobufUtil.createSnapshotDesc(snapshot));
    }
    // call post coproc hook
    if (cpHost != null) {
        cpHost.postSnapshot(snapshotPOJO, desc);
    }
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) SnapshotCreationException(org.apache.hadoop.hbase.snapshot.SnapshotCreationException) TablePartiallyOpenException(org.apache.hadoop.hbase.snapshot.TablePartiallyOpenException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) SnapshotExistsException(org.apache.hadoop.hbase.snapshot.SnapshotExistsException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TableName(org.apache.hadoop.hbase.TableName)

Aggregations

SnapshotCreationException (org.apache.hadoop.hbase.snapshot.SnapshotCreationException)6 IOException (java.io.IOException)5 TableName (org.apache.hadoop.hbase.TableName)4 FileNotFoundException (java.io.FileNotFoundException)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)2 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)2 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)2 IsSnapshotDoneRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest)2 IsSnapshotDoneResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse)2 RestoreSnapshotResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.RestoreSnapshotResponse)2 SnapshotResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SnapshotResponse)2 HBaseSnapshotException (org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)2 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)2 SnapshotExistsException (org.apache.hadoop.hbase.snapshot.SnapshotExistsException)2 TablePartiallyOpenException (org.apache.hadoop.hbase.snapshot.TablePartiallyOpenException)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 InterruptedIOException (java.io.InterruptedIOException)1 ArrayList (java.util.ArrayList)1