Search in sources :

Example 1 with DeadlineExceededException

use of alluxio.exception.status.DeadlineExceededException 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 2 with DeadlineExceededException

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

Example 3 with DeadlineExceededException

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

the class RegisterStreamer method registerInternal.

private void registerInternal() throws InterruptedException, DeadlineExceededException, CancelledException, InternalException {
    int iter = 0;
    while (hasNext()) {
        // Send a request when the master ACKs the previous one
        LOG.debug("Worker {} - Acquiring one token to send the next batch", mWorkerId);
        Instant start = Instant.now();
        if (!mBucket.tryAcquire(mResponseTimeoutMs, TimeUnit.MILLISECONDS)) {
            throw new DeadlineExceededException(String.format("No response from master for more than %dms during the stream!", mResponseTimeoutMs));
        }
        Instant end = Instant.now();
        LOG.debug("Worker {} - master ACK received in {}ms, sending the next batch {}", mWorkerId, Duration.between(start, end).toMillis(), iter);
        // Send the request
        RegisterWorkerPRequest request = next();
        mWorkerRequestObserver.onNext(request);
        if (mFinishLatch.getCount() == 0) {
            abort();
        }
        iter++;
    }
    // If the master side is closed before the client side, there is a problem
    if (mFinishLatch.getCount() == 0) {
        abort();
    }
    // Wait for all batches have been ACK-ed by the master before completing the client side
    if (!mAckLatch.await(mResponseTimeoutMs * MAX_BATCHES_IN_FLIGHT, TimeUnit.MILLISECONDS)) {
        long receivedCount = mBlockMapIterator.getBatchCount() - mAckLatch.getCount();
        throw new DeadlineExceededException(String.format("All batches have been sent to the master but only received %d ACKs!", receivedCount));
    }
    LOG.info("Worker {} - All requests have been sent. Completing the client side.", mWorkerId);
    mWorkerRequestObserver.onCompleted();
    LOG.info("Worker {} - Waiting on the master side to complete", mWorkerId);
    if (!mFinishLatch.await(mCompleteTimeoutMs, TimeUnit.MILLISECONDS)) {
        throw new DeadlineExceededException(String.format("All batches have been received by the master but the master failed" + " to complete the registration in %dms!", mCompleteTimeoutMs));
    }
    // If the master failed in completing the request, there will also be an error
    if (mError.get() != null) {
        Throwable t = mError.get();
        LOG.error("Worker {} - Received an error from the master on completion", mWorkerId, t);
        throw new InternalException(t);
    }
    LOG.info("Worker {} - Finished registration with a stream", mWorkerId);
}
Also used : Instant(java.time.Instant) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) InternalException(alluxio.exception.status.InternalException)

Example 4 with DeadlineExceededException

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

the class TieredBlockStore method removeBlockInternal.

@VisibleForTesting
BlockMeta removeBlockInternal(long sessionId, long blockId, BlockStoreLocation location, long timeoutMs) throws InvalidWorkerStateException, BlockDoesNotExistException, IOException {
    long lockId = mLockManager.tryLockBlock(sessionId, blockId, BlockLockType.WRITE, timeoutMs, TimeUnit.MILLISECONDS);
    if (lockId == BlockWorker.INVALID_LOCK_ID) {
        throw new DeadlineExceededException(String.format("Can not acquire lock to remove block %d for session %d after %d ms", blockId, sessionId, REMOVE_BLOCK_TIMEOUT_MS));
    }
    BlockMeta blockMeta;
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        if (mMetaManager.hasTempBlockMeta(blockId)) {
            throw new InvalidWorkerStateException(ExceptionMessage.REMOVE_UNCOMMITTED_BLOCK, blockId);
        }
        blockMeta = mMetaManager.getBlockMeta(blockId);
        if (!blockMeta.getBlockLocation().belongsTo(location)) {
            throw new BlockDoesNotExistException(ExceptionMessage.BLOCK_NOT_FOUND_AT_LOCATION, blockId, location);
        }
    } catch (Exception e) {
        mLockManager.unlockBlock(lockId);
        throw e;
    }
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        removeBlockFileAndMeta(blockMeta);
    } finally {
        mLockManager.unlockBlock(lockId);
    }
    return blockMeta;
}
Also used : LockResource(alluxio.resource.LockResource) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) IOException(java.io.IOException) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with DeadlineExceededException

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

the class PollingMasterInquireClient method getAddress.

@Nullable
private InetSocketAddress getAddress() {
    // Iterate over the masters and try to connect to each of their RPC ports.
    List<InetSocketAddress> addresses;
    if (mConfiguration.getBoolean(PropertyKey.USER_RPC_SHUFFLE_MASTERS_ENABLED)) {
        addresses = Lists.newArrayList(mConnectDetails.getAddresses());
        Collections.shuffle(addresses);
    } else {
        addresses = mConnectDetails.getAddresses();
    }
    for (InetSocketAddress address : addresses) {
        try {
            LOG.debug("Checking whether {} is listening for RPCs", address);
            pingMetaService(address);
            LOG.debug("Successfully connected to {}", address);
            return address;
        } catch (UnavailableException e) {
            LOG.debug("Failed to connect to {}", address);
            continue;
        } catch (DeadlineExceededException e) {
            LOG.debug("Timeout while connecting to {}", address);
            continue;
        } catch (CancelledException e) {
            LOG.debug("Cancelled while connecting to {}", address);
            continue;
        } catch (AlluxioStatusException e) {
            LOG.error("Error while connecting to {}. {}", address, e);
            // Breaking the loop on non filtered error.
            break;
        }
    }
    return null;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) CancelledException(alluxio.exception.status.CancelledException) UnavailableException(alluxio.exception.status.UnavailableException) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) Nullable(javax.annotation.Nullable)

Aggregations

DeadlineExceededException (alluxio.exception.status.DeadlineExceededException)5 CancelledException (alluxio.exception.status.CancelledException)3 LockResource (alluxio.resource.LockResource)2 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)1 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)1 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 InternalException (alluxio.exception.status.InternalException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 RegisterWorkerPRequest (alluxio.grpc.RegisterWorkerPRequest)1 BlockMeta (alluxio.worker.block.meta.BlockMeta)1 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Instant (java.time.Instant)1 Nullable (javax.annotation.Nullable)1