Search in sources :

Example 1 with CancelledException

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

the class UfsJournal method checkpoint.

/**
 * Creates a checkpoint in this ufs journal.
 */
public synchronized void checkpoint() throws IOException {
    long nextSequenceNumber = getNextSequenceNumberToWrite();
    if (nextSequenceNumber == getNextSequenceNumberToCheckpoint()) {
        LOG.info("{}: No entries have been written since the last checkpoint.", mMaster.getName());
        return;
    }
    try (UfsJournalCheckpointWriter journalWriter = getCheckpointWriter(nextSequenceNumber)) {
        LOG.info("{}: Writing checkpoint [sequence number {}].", mMaster.getName(), nextSequenceNumber);
        mMaster.writeToCheckpoint(journalWriter);
        LOG.info("{}: Finished checkpoint [sequence number {}].", mMaster.getName(), nextSequenceNumber);
        mEntriesSinceLastCheckPoint = 0;
        mLastCheckPointTime = System.currentTimeMillis();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new CancelledException(mMaster.getName() + ": Checkpoint is interrupted");
    }
}
Also used : CancelledException(alluxio.exception.status.CancelledException)

Example 2 with CancelledException

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

the class CacheRequestManager method submitRequest.

/**
 * Handles a request to cache a block. If it's async cache, it wouldn't throw exception.
 *
 * @param request the cache request fields will be available
 */
public void submitRequest(CacheRequest request) throws AlluxioException, IOException {
    CACHE_REQUESTS.inc();
    long blockId = request.getBlockId();
    boolean async = request.getAsync();
    if (mActiveCacheRequests.putIfAbsent(blockId, request) != null) {
        // This block is already planned and just just return.
        if (async) {
            LOG.debug("request already planned: {}", request);
        } else {
            try {
                CommonUtils.waitFor("block to be loaded", () -> !mActiveCacheRequests.containsKey(blockId), WaitForOptions.defaults().setTimeoutMs(30 * Constants.SECOND_MS));
            } catch (InterruptedException e) {
                throw new CancelledException("Fail to finish cache request synchronously. " + "Interrupted while waiting for block to be loaded by another request.", e);
            } catch (TimeoutException e) {
                throw new CancelledException("Fail to finish cache request synchronously due to timeout", e);
            }
        }
        return;
    }
    if (!async) {
        CACHE_REQUESTS_SYNC.inc();
    } else {
        CACHE_REQUESTS_ASYNC.inc();
    }
    Future<Void> future = null;
    try {
        future = mCacheExecutor.submit(new CacheTask(request));
    } catch (RejectedExecutionException e) {
        // RejectedExecutionException may be thrown in extreme cases when the
        // gRPC thread pool is drained due to highly concurrent caching workloads. In these cases,
        // return as async caching is at best effort.
        mNumRejected.incrementAndGet();
        SAMPLING_LOG.warn(String.format("Failed to cache block locally as the thread pool is at capacity." + " To increase, update the parameter '%s'. numRejected: {} error: {}", PropertyKey.Name.WORKER_NETWORK_ASYNC_CACHE_MANAGER_THREADS_MAX), mNumRejected.get(), e.toString());
        mActiveCacheRequests.remove(blockId);
        if (!async) {
            throw new CancelledException(String.format("Fail to finish cache request synchronously as the thread pool is at capacity." + " To increase the capacity, set the parameter '%s' and '%s' higher. ", PropertyKey.Name.WORKER_NETWORK_ASYNC_CACHE_MANAGER_THREADS_MAX, PropertyKey.Name.WORKER_NETWORK_ASYNC_CACHE_MANAGER_QUEUE_MAX), e);
        }
    }
    if (future != null && !async) {
        try {
            future.get();
        } catch (ExecutionException e) {
            CACHE_FAILED_BLOCKS.inc();
            Throwable cause = e.getCause();
            if (cause instanceof AlluxioException) {
                throw new AlluxioException(cause.getMessage(), cause);
            } else {
                throw new IOException(cause);
            }
        } catch (InterruptedException e) {
            throw new CancelledException("Fail to finish cache request synchronously. Interrupted while waiting for response.", e);
        }
    }
}
Also used : CancelledException(alluxio.exception.status.CancelledException) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) AlluxioException(alluxio.exception.AlluxioException)

Example 3 with CancelledException

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

the class RaftJournalSystem method checkpoint.

@Override
public synchronized void checkpoint() throws IOException {
    // snapshots from standby master
    try (RaftJournalAppender client = new RaftJournalAppender(mServer, this::createClient, mRawClientId, ServerConfiguration.global())) {
        mSnapshotAllowed.set(true);
        catchUp(mStateMachine, client);
        mStateMachine.takeLocalSnapshot();
    // TODO(feng): maybe prune logs after snapshot
    } catch (TimeoutException e) {
        LOG.warn("Timeout while performing snapshot: {}", e.toString());
        throw new IOException("Timeout while performing snapshot", e);
    } catch (InterruptedException e) {
        LOG.warn("Interrupted while performing snapshot: {}", e.toString());
        Thread.currentThread().interrupt();
        throw new CancelledException("Interrupted while performing snapshot", e);
    } finally {
        mSnapshotAllowed.set(false);
    }
}
Also used : CancelledException(alluxio.exception.status.CancelledException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with CancelledException

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

the class GrpcBlockingStream method receive.

/**
 * Receives a response from the server. Will wait until a response is received, or
 * throw an exception if times out.
 *
 * @param timeoutMs maximum time to wait before giving up and throwing
 *                  a {@link DeadlineExceededException}
 * @return the response message, or null if the inbound stream is completed
 * @throws IOException if any error occurs
 */
public ResT receive(long timeoutMs) throws IOException {
    if (mCompleted) {
        return null;
    }
    if (mCanceled) {
        throw new CancelledException(formatErrorMessage("Stream is already canceled."));
    }
    long startMs = System.currentTimeMillis();
    while (true) {
        long waitedForMs = System.currentTimeMillis() - startMs;
        if (waitedForMs >= timeoutMs) {
            throw new DeadlineExceededException(formatErrorMessage("Timeout waiting for response after %dms. clientClosed: %s clientCancelled: %s " + "serverClosed: %s", timeoutMs, mClosed, mCanceled, mClosedFromRemote));
        }
        // Wait for a minute max
        long waitMs = Math.min(timeoutMs - waitedForMs, Constants.MINUTE_MS);
        try {
            Object response = mResponses.poll(waitMs, TimeUnit.MILLISECONDS);
            if (response == null) {
                // The stream could have errored while we were waiting
                checkError();
                // Log a warning before looping again
                LOG.warn("Client did not receive message from stream, will wait again. totalWaitMs: {} " + "clientClosed: {} clientCancelled: {} serverClosed: {} description: {}", System.currentTimeMillis() - startMs, mClosed, mCanceled, mClosedFromRemote, mDescription);
                continue;
            }
            if (response == mResponseObserver) {
                mCompleted = true;
                return null;
            }
            checkError();
            return (ResT) response;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new CancelledException(formatErrorMessage("Interrupted while waiting for response."), e);
        }
    }
}
Also used : CancelledException(alluxio.exception.status.CancelledException) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException)

Example 5 with CancelledException

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

the class GrpcBlockingStream method send.

/**
 * Sends a request. Will wait until the stream is ready before sending or timeout if the
 * given timeout is reached.
 *
 * @param request the request
 * @param timeoutMs maximum wait time before throwing a {@link DeadlineExceededException}
 * @throws IOException if any error occurs
 */
public void send(ReqT request, long timeoutMs) throws IOException {
    if (mClosed || mCanceled || mClosedFromRemote) {
        throw new CancelledException(formatErrorMessage("Failed to send request %s: stream is already closed or cancelled. clientClosed: %s " + "clientCancelled: %s serverClosed: %s", LogUtils.truncateMessageLineLength(request), mClosed, mCanceled, mClosedFromRemote));
    }
    try (LockResource lr = new LockResource(mLock)) {
        long startMs = System.currentTimeMillis();
        while (true) {
            checkError();
            if (mRequestObserver.isReady()) {
                break;
            }
            long waitedForMs = System.currentTimeMillis() - startMs;
            if (waitedForMs >= timeoutMs) {
                throw new DeadlineExceededException(formatErrorMessage("Timeout sending request %s after %dms. clientClosed: %s clientCancelled: %s " + "serverClosed: %s", LogUtils.truncateMessageLineLength(request), timeoutMs, mClosed, mCanceled, mClosedFromRemote));
            }
            try {
                // Wait for a minute max
                long awaitMs = Math.min(timeoutMs - waitedForMs, Constants.MINUTE_MS);
                if (!mReadyOrFailed.await(awaitMs, TimeUnit.MILLISECONDS)) {
                    // Log a warning before looping again
                    LOG.warn("Stream is not ready for client to send request, will wait again. totalWaitMs: {} " + "clientClosed: {} clientCancelled: {} serverClosed: {} description: {}", System.currentTimeMillis() - startMs, mClosed, mCanceled, mClosedFromRemote, mDescription);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new CancelledException(formatErrorMessage("Failed to send request %s: interrupted while waiting for server.", LogUtils.truncateMessageLineLength(request)), e);
            }
        }
    }
    mRequestObserver.onNext(request);
}
Also used : LockResource(alluxio.resource.LockResource) CancelledException(alluxio.exception.status.CancelledException) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException)

Aggregations

CancelledException (alluxio.exception.status.CancelledException)6 DeadlineExceededException (alluxio.exception.status.DeadlineExceededException)3 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 AlluxioException (alluxio.exception.AlluxioException)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 LockResource (alluxio.resource.LockResource)1 InetSocketAddress (java.net.InetSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Nullable (javax.annotation.Nullable)1