use of alluxio.wire.BackupStatus in project alluxio by Alluxio.
the class BackupLeaderRole method backup.
@Override
public BackupStatus backup(BackupPRequest request, StateLockOptions stateLockOptions) throws AlluxioException {
// Whether to delegate remote to a standby master.
boolean delegateBackup;
// Will be populated with initiated id if no back-up in progress.
UUID backupId;
// Initiate new backup status under lock.
try (LockResource initiateLock = new LockResource(mBackupInitiateLock)) {
if (mBackupTracker.inProgress()) {
throw new BackupException("Backup in progress");
}
// Whether to attempt to delegate backup to a backup worker.
delegateBackup = ServerConfiguration.getBoolean(PropertyKey.MASTER_BACKUP_DELEGATION_ENABLED) && ConfigurationUtils.isHaMode(ServerConfiguration.global());
// unless `AllowLeader` flag in the backup request is set.
if (delegateBackup && mBackupWorkerHostNames.size() == 0) {
if (request.getOptions().getAllowLeader()) {
delegateBackup = false;
} else {
throw new BackupDelegationException("No master found to delegate backup.");
}
}
// Initialize backup status.
mBackupTracker.reset();
mBackupTracker.updateState(BackupState.Initiating);
mBackupTracker.updateHostname(NetworkAddressUtils.getLocalHostName((int) ServerConfiguration.global().getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS)));
// Store backup id to query later for async requests.
backupId = mBackupTracker.getCurrentStatus().getBackupId();
}
// Initiate the backup.
if (delegateBackup) {
// Fail the backup if delegation failed.
if (!scheduleRemoteBackup(backupId, request, stateLockOptions)) {
LOG.error("Failed to schedule remote backup.");
AlluxioException err = new BackupDelegationException("Failed to delegate the backup.");
mBackupTracker.updateError(err);
// Throw here for failing the backup call.
throw err;
}
} else {
scheduleLocalBackup(request, stateLockOptions);
}
// Return immediately if async is requested.
if (request.getOptions().getRunAsync()) {
// Client will always see 'Initiating' state first.
return new BackupStatus(backupId, BackupState.Initiating);
}
// Wait until backup is completed.
mBackupTracker.waitUntilFinished();
return mBackupTracker.getStatus(backupId);
}
use of alluxio.wire.BackupStatus in project alluxio by Alluxio.
the class BackupWorkerRole method handleRequestMessage.
/**
* Handler for backup request message. It's used in standby master.
*/
private CompletableFuture<Void> handleRequestMessage(BackupRequestMessage requestMsg) {
LOG.info("Received backup message: {}", requestMsg);
Preconditions.checkState(!mBackupTracker.inProgress(), "Backup in progress");
// Create a completed future for returning form this handler.
// This future is only used for providing a receipt of message.
CompletableFuture<Void> msgFuture = CompletableFuture.completedFuture(null);
// Reset backup tracker.
mBackupTracker.reset();
// Update current backup status with given backup id.
mBackupTracker.update(new BackupStatus(requestMsg.getBackupId(), BackupState.Initiating));
mBackupTracker.updateHostname(NetworkAddressUtils.getLocalHostName((int) ServerConfiguration.global().getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS)));
// Start sending backup progress to leader.
startHeartbeatThread();
// Cancel timeout task created by suspend message handler.
if (!mBackupTimeoutTask.cancel(true)) {
LOG.warn("Journal has been resumed due to a time-out");
mBackupTracker.updateError(new BackupException("Journal has been resumed due to a time-out"));
return msgFuture;
}
// Spawn a task for advancing journals to target sequences, then taking the backup.
mBackupFuture = mExecutorService.submit(() -> {
// Mark state as transitioning.
mBackupTracker.updateState(BackupState.Transitioning);
try {
LOG.info("Initiating catching up of journals to consistent sequences before starting backup. {}", requestMsg.getJournalSequences());
CatchupFuture catchupFuture = mJournalSystem.catchup(requestMsg.getJournalSequences());
CompletableFuture.runAsync(() -> catchupFuture.waitTermination()).get(BACKUP_ABORT_AFTER_TRANSITION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
LOG.info("Journal transition completed. Taking a backup.");
mBackupTracker.updateState(BackupState.Running);
AlluxioURI backupUri = takeBackup(requestMsg.getBackupRequest(), mBackupTracker.getEntryCounter());
mBackupTracker.updateBackupUri(backupUri);
mBackupTracker.updateState(BackupState.Completed);
// Wait until backup heartbeats are completed.
try {
mBackupProgressFuture.get();
} catch (Exception e) {
LOG.warn("Failed to wait for backup heartbeat completion. ", e);
}
} catch (InterruptedException e) {
LOG.error("Backup interrupted at worker", e);
mBackupTracker.updateError(new BackupException("Backup interrupted at worker", e));
} catch (Exception e) {
LOG.error("Backup failed at worker", e);
mBackupTracker.updateError(new BackupException(String.format("Backup failed at worker: %s", e.getMessage()), e));
} finally {
enforceResumeJournals();
}
});
return msgFuture;
}
use of alluxio.wire.BackupStatus in project alluxio by Alluxio.
the class BackupTracker method reset.
/**
* Resets this tracker.
*/
public void reset() {
LOG.info("Resetting backup tracker.");
try (LockResource statusLock = new LockResource(mStatusLock)) {
// Set error for backup in-progress.
if (inProgress()) {
LOG.info("Resetting the pending backup.");
updateError(new BackupException("Backup reset by tracker"));
}
// Reset current backup status.
mBackupStatus = new BackupStatus(BackupState.None);
mEntryCounter = new AtomicLong(0);
mCompletion = SettableFuture.create();
}
}
use of alluxio.wire.BackupStatus in project alluxio by Alluxio.
the class BackupCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
String[] args = cl.getArgs();
BackupPRequest.Builder opts = BackupPRequest.newBuilder();
if (args.length >= 1) {
opts.setTargetDirectory(args[0]);
}
opts.setOptions(BackupPOptions.newBuilder().setRunAsync(true).setLocalFileSystem(cl.hasOption(LOCAL_OPTION.getLongOpt())).setAllowLeader(cl.hasOption(ALLOW_LEADER_OPTION.getLongOpt())));
// Take backup in async mode.
BackupStatus status = mMetaClient.backup(opts.build());
UUID backupId = status.getBackupId();
do {
clearProgressLine();
// Backup could be after a fail-over.
if (status.getState() == BackupState.None) {
mPrintStream.printf("Backup lost. Please check Alluxio logs.%n");
return -1;
}
if (status.getState() == BackupState.Completed) {
break;
} else if (status.getState() == BackupState.Failed) {
throw AlluxioStatusException.fromAlluxioException(status.getError());
} else {
// Generate progress line that will be replaced until backup is finished.
String progressMessage = String.format(" Backup state: %s", status.getState());
// Start showing entry count once backup started running.
if (status.getState() == BackupState.Running) {
progressMessage += String.format(" | Entries processed: %d", status.getEntryCount());
}
mPrintStream.write(progressMessage.getBytes());
mPrintStream.write("\r".getBytes());
mPrintStream.flush();
}
// Sleep half a sec before querying status again.
try {
Thread.sleep(500);
status = mMetaClient.getBackupStatus(backupId);
} catch (InterruptedException ie) {
throw new RuntimeException("Interrupted while waiting for backup completion.");
} finally {
// In case exception is thrown.
clearProgressLine();
}
} while (true);
clearProgressLine();
// Print final state.
mPrintStream.printf("Backup Host : %s%n", status.getHostname());
mPrintStream.printf("Backup URI : %s%n", status.getBackupUri());
mPrintStream.printf("Backup Entry Count : %d%n", status.getEntryCount());
return 0;
}
Aggregations