Search in sources :

Example 1 with BackupDelegationException

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);
}
Also used : BackupException(alluxio.exception.BackupException) LockResource(alluxio.resource.LockResource) BackupDelegationException(alluxio.exception.BackupDelegationException) UUID(java.util.UUID) AlluxioException(alluxio.exception.AlluxioException) BackupStatus(alluxio.wire.BackupStatus)

Aggregations

AlluxioException (alluxio.exception.AlluxioException)1 BackupDelegationException (alluxio.exception.BackupDelegationException)1 BackupException (alluxio.exception.BackupException)1 LockResource (alluxio.resource.LockResource)1 BackupStatus (alluxio.wire.BackupStatus)1 UUID (java.util.UUID)1