* @throws RestoreSnapshotException if snapshot failed to be restored
* @throws IllegalArgumentException if the restore request is formatted incorrectly
*/
private void internalRestoreSnapshot(final String snapshotName, final String tableName)
throws IOException, RestoreSnapshotException {
HSnapshotDescription snapshot = new HSnapshotDescription(
SnapshotDescription.newBuilder().setName(snapshotName).setTable(tableName).build());
try {
// actually restore the snapshot
getMaster().restoreSnapshot(snapshot);
final long maxPauseTime = 5000;
boolean done = false;
int tries = 0;
while (!done) {
try {
// sleep a backoff <= pauseTime amount
long sleep = getPauseTime(tries++);
sleep = sleep > maxPauseTime ? maxPauseTime : sleep;
LOG.debug(tries + ") Sleeping: " + sleep + " ms while we wait for snapshot restore to complete.");
Thread.sleep(sleep);
} catch (InterruptedException e) {
LOG.debug("Interrupted while waiting for snapshot " + snapshot + " restore to complete");
Thread.currentThread().interrupt();
}
LOG.debug("Getting current status of snapshot restore from master...");
done = getMaster().isRestoreSnapshotDone(snapshot);
}
if (!done) {
throw new RestoreSnapshotException("Snapshot '" + snapshot.getName() + "' wasn't restored.");
}
} catch (RemoteException e) {
throw RemoteExceptionHandler.decodeRemoteException(e);
}
}