use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class AuthenticatedChannelClientDriver method waitUntilChannelAuthenticated.
private void waitUntilChannelAuthenticated(long timeoutMs) throws AlluxioStatusException {
try {
// Wait until authentication status changes.
mChannelAuthenticatedFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
mChannelAuthenticated = true;
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw AlluxioStatusException.fromThrowable(ie);
} catch (ExecutionException e) {
AlluxioStatusException statExc = AlluxioStatusException.fromThrowable(e.getCause());
// Unimplemented is returned if server doesn't provide authentication service.
if (statExc.getStatusCode() == Status.Code.UNIMPLEMENTED) {
throw new UnauthenticatedException("Authentication is disabled on target server.");
}
throw statExc;
} catch (TimeoutException e) {
throw new UnavailableException(e);
}
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class MasterJournalContext method waitForJournalFlush.
/**
* Waits for the flush counter to be flushed to the journal. If the counter is
* {@link #INVALID_FLUSH_COUNTER}, this is a noop.
*/
private void waitForJournalFlush() throws UnavailableException {
if (mFlushCounter == INVALID_FLUSH_COUNTER) {
// Check this before the precondition.
return;
}
RetryPolicy retry = new TimeoutRetry(FLUSH_RETRY_TIMEOUT_MS, FLUSH_RETRY_INTERVAL_MS);
while (retry.attempt()) {
try {
mAsyncJournalWriter.flush(mFlushCounter);
return;
} catch (NotLeaderException | JournalClosedException e) {
throw new UnavailableException(String.format("Failed to complete request: %s", e.getMessage()), e);
} catch (AlluxioStatusException e) {
// written already
if (e.getStatus().equals(Status.CANCELLED)) {
LOG.warn("Journal flush interrupted because the RPC was cancelled. ", e);
} else {
LOG.warn("Journal flush failed. retrying...", e);
}
} catch (IOException e) {
if (e instanceof AlluxioStatusException && ((AlluxioStatusException) e).getStatusCode() == Status.Code.CANCELLED) {
throw new UnavailableException(String.format("Failed to complete request: %s", e.getMessage()), e);
}
LOG.warn("Journal flush failed. retrying...", e);
} catch (Throwable e) {
ProcessUtils.fatalError(LOG, e, "Journal flush failed");
}
}
ProcessUtils.fatalError(LOG, "Journal flush failed after %d attempts", retry.getAttemptCount());
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class AsyncJournalWriter method flush.
/**
* Submits a ticket to flush thread and waits until ticket is served.
*
* If the specified counter is already flushed, this is essentially a no-op.
*
* @param targetCounter the counter to flush
*/
public void flush(final long targetCounter) throws IOException, JournalClosedException {
// Return if flushed.
if (targetCounter <= mFlushCounter.get()) {
return;
}
// Submit the ticket for flush thread to process.
FlushTicket ticket = new FlushTicket(targetCounter);
mTicketSet.add(ticket);
try {
// Give a permit for flush thread to run.
mFlushSemaphore.release();
// Wait on the ticket until completed.
ticket.waitCompleted();
} catch (InterruptedException ie) {
// Interpret interruption as cancellation.
throw new AlluxioStatusException(Status.CANCELLED.withCause(ie));
} catch (Throwable e) {
// Filter, journal specific exception codes.
if (e instanceof IOException) {
throw (IOException) e;
}
if (e instanceof JournalClosedException) {
throw (JournalClosedException) e;
}
// Not expected. throw internal error.
throw new AlluxioStatusException(Status.INTERNAL.withCause(e));
} finally {
/*
* Client can only try to reacquire the permit it has given
* because the permit may or may not have been used by the flush thread.
*/
mFlushSemaphore.tryAcquire();
}
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class BlockReadHandler method handleStreamEndingException.
/**
* Handles any exception which should abort the client's read request.
*
* @param status the type of {@link Status} exception which should be returned to the user
*/
private void handleStreamEndingException(Status status) {
Long sessionId = mContext.getRequest() == null ? -1 : mContext.getRequest().getSessionId();
LogUtils.warnWithException(LOG, "Error occurred while handling read. sessionId: {}. Ending " + "stream", sessionId, status);
AlluxioStatusException statusExc = AlluxioStatusException.from(status);
try (LockResource lr = new LockResource(mLock)) {
if (mContext == null) {
mContext = createRequestContext(alluxio.grpc.ReadRequest.newBuilder().build());
}
setError(new Error(statusExc, true));
}
}
use of alluxio.exception.status.AlluxioStatusException in project alluxio by Alluxio.
the class ChannelAuthenticator method authenticate.
/**
* It builds an authenticated channel.
*
* @throws AlluxioStatusException
*/
public void authenticate() throws AlluxioStatusException {
LOG.debug("Authenticating channel: {}. AuthType: {}", mChannelKey.toStringShort(), mAuthType);
ChannelAuthenticationScheme authScheme = getChannelAuthScheme(mAuthType, mParentSubject, mChannelKey.getServerAddress().getSocketAddress());
try {
// Create client-side driver for establishing authenticated channel with the target.
mAuthDriver = new AuthenticatedChannelClientDriver(createSaslClientHandler(mChannelKey.getServerAddress(), authScheme, mParentSubject), mChannelKey);
// Initialize client-server authentication drivers.
SaslAuthenticationServiceGrpc.SaslAuthenticationServiceStub serverStub = SaslAuthenticationServiceGrpc.newStub(mConnection.getChannel());
StreamObserver<SaslMessage> requestObserver = serverStub.authenticate(mAuthDriver);
mAuthDriver.setServerObserver(requestObserver);
// Start authentication with the target. (This is blocking.)
long authTimeout = mConfiguration.getMs(PropertyKey.NETWORK_CONNECTION_AUTH_TIMEOUT);
mAuthDriver.startAuthenticatedChannel(authTimeout);
// Intercept authenticated channel with channel-id injector.
mConnection.interceptChannel(new ChannelIdInjector(mChannelKey.getChannelId()));
} catch (Throwable t) {
AlluxioStatusException e = AlluxioStatusException.fromThrowable(t);
// Build a pretty message for authentication failure.
String message = String.format("Channel authentication failed with code:%s. Channel: %s, AuthType: %s, Error: %s", e.getStatusCode().name(), mChannelKey.toStringShort(), mAuthType, e.toString());
throw AlluxioStatusException.from(Status.fromCode(e.getStatusCode()).withDescription(message).withCause(t));
}
}
Aggregations