Index: hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java =================================================================== --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (revision 1477634) +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (working copy) @@ -2371,6 +2371,7 @@ }).getDone(); } + private static final String RESTORE_DROP_ROLLBACK_SNAPSHOT="hbase.snapshot.restore.drop.rollback"; /** * Restore the specified snapshot on the original table. (The table must be disabled) * Before restoring the table, a new snapshot with the current table state is created. @@ -2383,12 +2384,30 @@ */ public void restoreSnapshot(final byte[] snapshotName) throws IOException, RestoreSnapshotException { - restoreSnapshot(Bytes.toString(snapshotName)); + restoreSnapshot(Bytes.toString(snapshotName), + conf.getBoolean(RESTORE_DROP_ROLLBACK_SNAPSHOT, true)); } /** * Restore the specified snapshot on the original table. (The table must be disabled) * Before restoring the table, a new snapshot with the current table state is created. + * In case of failure, the table will be rolled back to its original state. + * + * @param snapshotName name of the snapshot to restore + * @param dropRollbackSnapshot whether rollback snapshot should be dropped at the end of restore + * @throws IOException if a remote or network exception occurs + * @throws RestoreSnapshotException if snapshot failed to be restored + * @throws IllegalArgumentException if the restore request is formatted incorrectly + */ + public void restoreSnapshot(final byte[] snapshotName, final boolean dropRollbackSnapshot) + throws IOException, RestoreSnapshotException { + restoreSnapshot(Bytes.toString(snapshotName), dropRollbackSnapshot); + } + + /** + * Restore the specified snapshot on the original table. (The table must be disabled) + * Before restoring the table, a new snapshot (rollback snapshot) with the current table state is + * created. * In case of failure, the table will be rolled back to the its original state. * * @param snapshotName name of the snapshot to restore @@ -2398,7 +2417,24 @@ */ public void restoreSnapshot(final String snapshotName) throws IOException, RestoreSnapshotException { - String rollbackSnapshot = snapshotName + "-" + EnvironmentEdgeManager.currentTimeMillis(); + restoreSnapshot(snapshotName, conf.getBoolean(RESTORE_DROP_ROLLBACK_SNAPSHOT, true)); + } + + /** + * Restore the specified snapshot on the original table. (The table must be disabled) + * Before restoring the table, a new snapshot with the current table state is created. + * In case of failure, the table will be rolled back to the its original state. + * + * @param snapshotName name of the snapshot to restore + * @param dropRollbackSnapshot whether rollback snapshot should be dropped at the end of restore + * @throws IOException if a remote or network exception occurs + * @throws RestoreSnapshotException if snapshot failed to be restored + * @throws IllegalArgumentException if the restore request is formatted incorrectly + */ + public void restoreSnapshot(final String snapshotName, final boolean dropRollbackSnapshot) + throws IOException, RestoreSnapshotException { + String rollbackSnapshot = snapshotName + "-for-rollback-" + + EnvironmentEdgeManager.currentTimeMillis(); String tableName = null; for (SnapshotDescription snapshotInfo: listSnapshots()) { @@ -2433,6 +2469,14 @@ throw new RestoreSnapshotException(msg, ex); } } + if (dropRollbackSnapshot) { + try { + deleteSnapshot(rollbackSnapshot); + LOG.info("Deleted " + rollbackSnapshot); + } catch (IOException e) { + LOG.error("Failed to drop " + rollbackSnapshot, e); + } + } } /**