Search in sources :

Example 46 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class DefaultFileSystemMaster method removeBlocks.

private void removeBlocks(Collection<Long> blocks) throws IOException {
    if (blocks.isEmpty()) {
        return;
    }
    RetryPolicy retry = new CountingRetry(3);
    IOException lastThrown = null;
    while (retry.attempt()) {
        try {
            mBlockMaster.removeBlocks(blocks, true);
            return;
        } catch (UnavailableException e) {
            lastThrown = e;
        }
    }
    throw new IOException("Failed to remove deleted blocks from block master", lastThrown);
}
Also used : CountingRetry(alluxio.retry.CountingRetry) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 47 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class DefaultBlockMaster method getLostWorkersInfoList.

@Override
public List<WorkerInfo> getLostWorkersInfoList() throws UnavailableException {
    if (mSafeModeManager.isInSafeMode()) {
        throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
    }
    List<WorkerInfo> workerInfoList = new ArrayList<>(mLostWorkers.size());
    for (MasterWorkerInfo worker : mLostWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, null, false));
    }
    Collections.sort(workerInfoList, new WorkerInfo.LastContactSecComparator());
    return workerInfoList;
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) ArrayList(java.util.ArrayList) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo)

Example 48 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class DefaultBlockMaster method getWorkerReport.

@Override
public List<WorkerInfo> getWorkerReport(GetWorkerReportOptions options) throws UnavailableException, InvalidArgumentException {
    if (mSafeModeManager.isInSafeMode()) {
        throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
    }
    Set<MasterWorkerInfo> selectedLiveWorkers = new HashSet<>();
    Set<MasterWorkerInfo> selectedLostWorkers = new HashSet<>();
    WorkerRange workerRange = options.getWorkerRange();
    switch(workerRange) {
        case ALL:
            selectedLiveWorkers.addAll(mWorkers);
            selectedLostWorkers.addAll(mLostWorkers);
            break;
        case LIVE:
            selectedLiveWorkers.addAll(mWorkers);
            break;
        case LOST:
            selectedLostWorkers.addAll(mLostWorkers);
            break;
        case SPECIFIED:
            Set<String> addresses = options.getAddresses();
            Set<String> workerNames = new HashSet<>();
            selectedLiveWorkers = selectInfoByAddress(addresses, mWorkers, workerNames);
            selectedLostWorkers = selectInfoByAddress(addresses, mLostWorkers, workerNames);
            if (!addresses.isEmpty()) {
                String info = String.format("Unrecognized worker names: %s%n" + "Supported worker names: %s%n", addresses.toString(), workerNames.toString());
                throw new InvalidArgumentException(info);
            }
            break;
        default:
            throw new InvalidArgumentException("Unrecognized worker range: " + workerRange);
    }
    List<WorkerInfo> workerInfoList = new ArrayList<>(selectedLiveWorkers.size() + selectedLostWorkers.size());
    for (MasterWorkerInfo worker : selectedLiveWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, options.getFieldRange(), true));
    }
    for (MasterWorkerInfo worker : selectedLostWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, options.getFieldRange(), false));
    }
    return workerInfoList;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) UnavailableException(alluxio.exception.status.UnavailableException) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) WorkerRange(alluxio.client.block.options.GetWorkerReportOptions.WorkerRange) ArrayList(java.util.ArrayList) WorkerInfo(alluxio.wire.WorkerInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) HashSet(java.util.HashSet)

Example 49 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class AccessTimeUpdater method flushUpdates.

private void flushUpdates() {
    try (JournalContext context = mFileSystemMaster.createJournalContext()) {
        for (Iterator<Map.Entry<Long, Long>> iterator = mAccessTimeUpdates.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<Long, Long> inodeEntry = iterator.next();
            iterator.remove();
            UpdateInodeEntry entry = UpdateInodeEntry.newBuilder().setId(inodeEntry.getKey()).setLastAccessTimeMs(inodeEntry.getValue()).build();
            context.append(Journal.JournalEntry.newBuilder().setUpdateInode(entry).build());
        }
    } catch (UnavailableException e) {
        LOG.debug("Failed to flush access time updates.", e);
    }
}
Also used : UpdateInodeEntry(alluxio.proto.journal.File.UpdateInodeEntry) UpdateInodeEntry(alluxio.proto.journal.File.UpdateInodeEntry) JournalContext(alluxio.master.journal.JournalContext) UnavailableException(alluxio.exception.status.UnavailableException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 50 with UnavailableException

use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.

the class FaultTolerantAlluxioMasterProcess method gainPrimacy.

/**
 * Upgrades the master to primary mode.
 *
 * If the master loses primacy during the journal upgrade, this method will clean up the partial
 * upgrade, leaving the master in standby mode.
 *
 * @return whether the master successfully upgraded to primary
 */
private boolean gainPrimacy() throws Exception {
    LOG.info("Becoming a leader.");
    // Don't upgrade if this master's primacy is unstable.
    AtomicBoolean unstable = new AtomicBoolean(false);
    try (Scoped scoped = mLeaderSelector.onStateChange(state -> unstable.set(true))) {
        if (mLeaderSelector.getState() != State.PRIMARY) {
            LOG.info("Lost leadership while becoming a leader.");
            unstable.set(true);
        }
        stopMasters();
        LOG.info("Standby stopped");
        try (Timer.Context ctx = MetricsSystem.timer(MetricKey.MASTER_JOURNAL_GAIN_PRIMACY_TIMER.getName()).time()) {
            mJournalSystem.gainPrimacy();
        }
        // We only check unstable here because mJournalSystem.gainPrimacy() is the only slow method
        if (unstable.get()) {
            LOG.info("Terminating an unstable attempt to become a leader.");
            if (ServerConfiguration.getBoolean(PropertyKey.MASTER_JOURNAL_EXIT_ON_DEMOTION)) {
                stop();
            } else {
                losePrimacy();
            }
            return false;
        }
    }
    try {
        startMasters(true);
    } catch (UnavailableException e) {
        LOG.warn("Error starting masters: {}", e.toString());
        stopMasters();
        return false;
    }
    mServingThread = new Thread(() -> {
        try {
            startCommonServices();
            startLeaderServing(" (gained leadership)", " (lost leadership)");
        } catch (Throwable t) {
            Throwable root = Throwables.getRootCause(t);
            if ((root != null && (root instanceof InterruptedException)) || Thread.interrupted()) {
                return;
            }
            ProcessUtils.fatalError(LOG, t, "Exception thrown in main serving thread");
        }
    }, "MasterServingThread");
    LOG.info("Starting a server thread.");
    mServingThread.start();
    if (!waitForReady(10 * Constants.MINUTE_MS)) {
        ThreadUtils.logAllThreads();
        throw new RuntimeException("Alluxio master failed to come up");
    }
    LOG.info("Primary started");
    return true;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timer(com.codahale.metrics.Timer) UnavailableException(alluxio.exception.status.UnavailableException) Scoped(alluxio.util.interfaces.Scoped)

Aggregations

UnavailableException (alluxio.exception.status.UnavailableException)58 IOException (java.io.IOException)25 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)9 NotFoundException (alluxio.exception.status.NotFoundException)9 InetSocketAddress (java.net.InetSocketAddress)9 BlockInfo (alluxio.wire.BlockInfo)8 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 WorkerNetAddress (alluxio.wire.WorkerNetAddress)7 WorkerInfo (alluxio.wire.WorkerInfo)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Set (java.util.Set)6 RetryPolicy (alluxio.retry.RetryPolicy)5 TimeoutException (java.util.concurrent.TimeoutException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 ExceptionMessage (alluxio.exception.ExceptionMessage)4 InodeFile (alluxio.master.file.meta.InodeFile)4