use of alluxio.exception.BackupDelegationException 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);
}
Aggregations