Ejemplo n.º 1
0
  /**
   * Restore the specified snapshot. The restore will fail if the destination table has a snapshot
   * or restore in progress.
   *
   * @param reqSnapshot Snapshot Descriptor from request
   * @param tableName table to restore
   * @param snapshot Snapshot Descriptor
   * @param snapshotTableDesc Table Descriptor
   * @param nonceGroup unique value to prevent duplicated RPC
   * @param nonce unique value to prevent duplicated RPC
   * @return procId the ID of the restore snapshot procedure
   * @throws IOException
   */
  private long restoreSnapshot(
      final SnapshotDescription reqSnapshot,
      final TableName tableName,
      final SnapshotDescription snapshot,
      final HTableDescriptor snapshotTableDesc,
      final long nonceGroup,
      final long nonce)
      throws IOException {
    MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();

    if (master
        .getTableStateManager()
        .isTableState(TableName.valueOf(snapshot.getTable()), TableState.State.ENABLED)) {
      throw new UnsupportedOperationException(
          "Table '"
              + TableName.valueOf(snapshot.getTable())
              + "' must be disabled in order to "
              + "perform a restore operation.");
    }

    // call Coprocessor pre hook
    if (cpHost != null) {
      cpHost.preRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }

    long procId;
    try {
      procId = restoreSnapshot(snapshot, snapshotTableDesc, nonceGroup, nonce);
    } catch (IOException e) {
      LOG.error(
          "Exception occurred while restoring the snapshot "
              + snapshot.getName()
              + " as table "
              + tableName.getNameAsString(),
          e);
      throw e;
    }
    LOG.info("Restore snapshot=" + snapshot.getName() + " as table=" + tableName);

    if (cpHost != null) {
      cpHost.postRestoreSnapshot(reqSnapshot, snapshotTableDesc);
    }

    return procId;
  }