Search in sources :

Example 1 with BackupException

use of alluxio.exception.BackupException 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)

Example 2 with BackupException

use of alluxio.exception.BackupException 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;
}
Also used : BackupException(alluxio.exception.BackupException) CatchupFuture(alluxio.master.journal.CatchupFuture) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BackupException(alluxio.exception.BackupException) BackupStatus(alluxio.wire.BackupStatus) AlluxioURI(alluxio.AlluxioURI)

Example 3 with BackupException

use of alluxio.exception.BackupException 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();
    }
}
Also used : BackupException(alluxio.exception.BackupException) AtomicLong(java.util.concurrent.atomic.AtomicLong) LockResource(alluxio.resource.LockResource) BackupStatus(alluxio.wire.BackupStatus)

Example 4 with BackupException

use of alluxio.exception.BackupException in project alluxio by Alluxio.

the class BackupLeaderRole method scheduleLocalBackup.

/**
 * Schedule backup on this master.
 */
private void scheduleLocalBackup(BackupPRequest request, StateLockOptions stateLockOptions) {
    LOG.info("Scheduling backup at the backup-leader.");
    mLocalBackupFuture = mExecutorService.submit(() -> {
        try (LockResource stateLockResource = mStateLockManager.lockExclusive(stateLockOptions)) {
            mBackupTracker.updateState(BackupState.Running);
            AlluxioURI backupUri = takeBackup(request, mBackupTracker.getEntryCounter());
            mBackupTracker.updateBackupUri(backupUri);
            mBackupTracker.updateState(BackupState.Completed);
        } catch (Exception e) {
            LOG.error("Local backup failed at the backup-leader.", e);
            mBackupTracker.updateError(new BackupException(String.format("Local backup failed: %s", e.getMessage()), e));
        }
    });
}
Also used : BackupException(alluxio.exception.BackupException) LockResource(alluxio.resource.LockResource) BackupAbortedException(alluxio.exception.BackupAbortedException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) BackupException(alluxio.exception.BackupException) BackupDelegationException(alluxio.exception.BackupDelegationException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

BackupException (alluxio.exception.BackupException)4 AlluxioException (alluxio.exception.AlluxioException)3 LockResource (alluxio.resource.LockResource)3 BackupStatus (alluxio.wire.BackupStatus)3 AlluxioURI (alluxio.AlluxioURI)2 BackupDelegationException (alluxio.exception.BackupDelegationException)2 IOException (java.io.IOException)2 BackupAbortedException (alluxio.exception.BackupAbortedException)1 CatchupFuture (alluxio.master.journal.CatchupFuture)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1