Search in sources :

Example 21 with MasterCoprocessorHost

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

the class SnapshotManager method cloneSnapshot.

/**
   * Clone the specified snapshot.
   * The clone will fail if the destination table has a snapshot or restore in progress.
   *
   * @param reqSnapshot Snapshot Descriptor from request
   * @param tableName table to clone
   * @param snapshot Snapshot Descriptor
   * @param snapshotTableDesc Table Descriptor
   * @param nonceKey unique identifier to prevent duplicated RPC
   * @return procId the ID of the clone snapshot procedure
   * @throws IOException
   */
private long cloneSnapshot(final SnapshotDescription reqSnapshot, final TableName tableName, final SnapshotDescription snapshot, final HTableDescriptor snapshotTableDesc, final NonceKey nonceKey) throws IOException {
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    HTableDescriptor htd = new HTableDescriptor(tableName, snapshotTableDesc);
    if (cpHost != null) {
        cpHost.preCloneSnapshot(reqSnapshot, htd);
    }
    long procId;
    try {
        procId = cloneSnapshot(snapshot, htd, nonceKey);
    } catch (IOException e) {
        LOG.error("Exception occurred while cloning the snapshot " + snapshot.getName() + " as table " + tableName.getNameAsString(), e);
        throw e;
    }
    LOG.info("Clone snapshot=" + snapshot.getName() + " as table=" + tableName);
    if (cpHost != null) {
        cpHost.postCloneSnapshot(reqSnapshot, htd);
    }
    return procId;
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 22 with MasterCoprocessorHost

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

the class SnapshotManager method getCompletedSnapshots.

/**
   * Gets the list of all completed snapshots.
   * @param snapshotDir snapshot directory
   * @return list of SnapshotDescriptions
   * @throws IOException File system exception
   */
private List<SnapshotDescription> getCompletedSnapshots(Path snapshotDir) throws IOException {
    List<SnapshotDescription> snapshotDescs = new ArrayList<>();
    // first create the snapshot root path and check to see if it exists
    FileSystem fs = master.getMasterFileSystem().getFileSystem();
    if (snapshotDir == null)
        snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir);
    // if there are no snapshots, return an empty list
    if (!fs.exists(snapshotDir)) {
        return snapshotDescs;
    }
    // ignore all the snapshots in progress
    FileStatus[] snapshots = fs.listStatus(snapshotDir, new SnapshotDescriptionUtils.CompletedSnaphotDirectoriesFilter(fs));
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    // loop through all the completed snapshots
    for (FileStatus snapshot : snapshots) {
        Path info = new Path(snapshot.getPath(), SnapshotDescriptionUtils.SNAPSHOTINFO_FILE);
        // if the snapshot is bad
        if (!fs.exists(info)) {
            LOG.error("Snapshot information for " + snapshot.getPath() + " doesn't exist");
            continue;
        }
        FSDataInputStream in = null;
        try {
            in = fs.open(info);
            SnapshotDescription desc = SnapshotDescription.parseFrom(in);
            if (cpHost != null) {
                try {
                    cpHost.preListSnapshot(desc);
                } catch (AccessDeniedException e) {
                    LOG.warn("Current user does not have access to " + desc.getName() + " snapshot. " + "Either you should be owner of this snapshot or admin user.");
                    // Skip this and try for next snapshot
                    continue;
                }
            }
            snapshotDescs.add(desc);
            // call coproc post hook
            if (cpHost != null) {
                cpHost.postListSnapshot(desc);
            }
        } catch (IOException e) {
            LOG.warn("Found a corrupted snapshot " + snapshot.getPath(), e);
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
    return snapshotDescs;
}
Also used : Path(org.apache.hadoop.fs.Path) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) FileStatus(org.apache.hadoop.fs.FileStatus) ClientSnapshotDescriptionUtils(org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils) SnapshotDescriptionUtils(org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils) ArrayList(java.util.ArrayList) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.SnapshotDescription) IOException(java.io.IOException) FileSystem(org.apache.hadoop.fs.FileSystem) MasterFileSystem(org.apache.hadoop.hbase.master.MasterFileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Example 23 with MasterCoprocessorHost

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

the class SnapshotManager method takeSnapshot.

/**
   * Take a snapshot based on the enabled/disabled state of the table.
   *
   * @param snapshot
   * @throws HBaseSnapshotException when a snapshot specific exception occurs.
   * @throws IOException when some sort of generic IO exception occurs.
   */
public void takeSnapshot(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
    HTableDescriptor 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);
    }
    User user = RpcServer.getRequestUser();
    if (User.isHBaseSecurityEnabled(master.getConfiguration()) && user != null) {
        builder.setOwner(user.getShortName());
    }
    snapshot = builder.build();
    // call pre coproc hook
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    if (cpHost != null) {
        cpHost.preSnapshot(snapshot, 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)) {
        LOG.debug("Table enabled, starting distributed snapshot.");
        snapshotEnabledTable(snapshot);
        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)) {
        LOG.debug("Table is disabled, running snapshot entirely on master.");
        snapshotDisabledTable(snapshot);
        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(snapshot, desc);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) User(org.apache.hadoop.hbase.security.User) 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.HBaseProtos.SnapshotDescription) SnapshotExistsException(org.apache.hadoop.hbase.snapshot.SnapshotExistsException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 24 with MasterCoprocessorHost

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

the class SplitTableRegionProcedure method preSplitRegionBeforePONR.

/**
   * Post split region actions before the Point-of-No-Return step
   * @param env MasterProcedureEnv
   **/
private void preSplitRegionBeforePONR(final MasterProcedureEnv env) throws IOException, InterruptedException {
    final List<Mutation> metaEntries = new ArrayList<>();
    final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
    if (cpHost != null) {
        if (cpHost.preSplitBeforePONRAction(getSplitRow(), metaEntries, getUser())) {
            throw new IOException("Coprocessor bypassing region " + parentHRI.getRegionNameAsString() + " split.");
        }
        try {
            for (Mutation p : metaEntries) {
                HRegionInfo.parseRegionName(p.getRow());
            }
        } catch (IOException e) {
            LOG.error("Row key of mutation from coprocessor is not parsable as region name." + "Mutations from coprocessor should only for hbase:meta table.");
            throw e;
        }
    }
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.client.Mutation) InterruptedIOException(java.io.InterruptedIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 25 with MasterCoprocessorHost

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

the class TruncateTableProcedure method postTruncate.

private void postTruncate(final MasterProcedureEnv env) throws IOException, InterruptedException {
    final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
    if (cpHost != null) {
        final TableName tableName = getTableName();
        cpHost.postCompletedTruncateTableAction(tableName, getUser());
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost)

Aggregations

MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)37 Test (org.junit.Test)15 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)12 TableName (org.apache.hadoop.hbase.TableName)11 HMaster (org.apache.hadoop.hbase.master.HMaster)11 IOException (java.io.IOException)9 RegionServerCoprocessorHost (org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost)7 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 BeforeClass (org.junit.BeforeClass)6 Admin (org.apache.hadoop.hbase.client.Admin)5 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)4 ArrayList (java.util.ArrayList)3 Configuration (org.apache.hadoop.conf.Configuration)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)3 InterruptedIOException (java.io.InterruptedIOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2