Example #1
0
 /** Remove the procedures that are marked as finished */
 private synchronized void cleanupCompletedRestoreInMap() {
   ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
   Iterator<Map.Entry<TableName, Long>> it = restoreTableToProcIdMap.entrySet().iterator();
   while (it.hasNext()) {
     Map.Entry<TableName, Long> entry = it.next();
     Long procId = entry.getValue();
     if (procExec.isRunning() && procExec.isFinished(procId)) {
       it.remove();
     }
   }
 }
Example #2
0
  /**
   * 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 nonceGroup unique value to prevent duplicated RPC
   * @param nonce unique value to prevent duplicated RPC
   * @return procId the ID of the restore snapshot procedure
   */
  private synchronized long restoreSnapshot(
      final SnapshotDescription snapshot,
      final HTableDescriptor hTableDescriptor,
      final long nonceGroup,
      final long nonce)
      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 RestoreSnapshotProcedure(
                      master.getMasterProcedureExecutor().getEnvironment(),
                      hTableDescriptor,
                      snapshot),
                  nonceGroup,
                  nonce);
      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);
    }
  }
Example #3
0
 /**
  * Verify if the restore of the specified table is in progress.
  *
  * @param tableName table under restore
  * @return <tt>true</tt> if there is a restore in progress of the specified table.
  */
 private synchronized boolean isRestoringTable(final TableName tableName) {
   Long procId = this.restoreTableToProcIdMap.get(tableName);
   if (procId == null) {
     return false;
   }
   ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
   if (procExec.isRunning() && !procExec.isFinished(procId)) {
     return true;
   } else {
     this.restoreTableToProcIdMap.remove(tableName);
     return false;
   }
 }