Skip to content

Commit

Permalink
Update definition of AlluxioTException
Browse files Browse the repository at this point in the history
  • Loading branch information
aaudiber committed Apr 15, 2017
1 parent 8bc0101 commit de265e0
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 347 deletions.
Expand Up @@ -22,7 +22,7 @@
import alluxio.exception.ExceptionMessage; import alluxio.exception.ExceptionMessage;
import alluxio.exception.UfsBlockAccessTokenUnavailableException; import alluxio.exception.UfsBlockAccessTokenUnavailableException;
import alluxio.exception.WorkerOutOfSpaceException; import alluxio.exception.WorkerOutOfSpaceException;
import alluxio.exception.status.UnavailableException; import alluxio.exception.status.AlluxioStatusException;
import alluxio.metrics.MetricsSystem; import alluxio.metrics.MetricsSystem;
import alluxio.retry.CountingRetry; import alluxio.retry.CountingRetry;
import alluxio.retry.ExponentialBackoffRetry; import alluxio.retry.ExponentialBackoffRetry;
Expand Down Expand Up @@ -349,12 +349,9 @@ public void sessionHeartbeat(RetryPolicy retryPolicy) throws IOException, Interr
Metrics.BLOCK_WORKER_HEATBEATS.inc(); Metrics.BLOCK_WORKER_HEATBEATS.inc();
return; return;
} catch (AlluxioTException e) { } catch (AlluxioTException e) {
AlluxioException ae = AlluxioException.fromThrift(e); AlluxioStatusException se = AlluxioStatusException.fromThrift(e);
LOG.warn(ae.getMessage()); LOG.warn(se.getMessage());
throw new IOException(ae); throw new IOException(se);
} catch (UnavailableException e) {
LOG.warn(e.getMessage());
throw new IOException(e);
} catch (TException e) { } catch (TException e) {
client.getOutputProtocol().getTransport().close(); client.getOutputProtocol().getTransport().close();
exception = e; exception = e;
Expand Down
19 changes: 12 additions & 7 deletions core/common/src/main/java/alluxio/AbstractClient.java
Expand Up @@ -15,7 +15,8 @@
import alluxio.exception.ConnectionFailedException; import alluxio.exception.ConnectionFailedException;
import alluxio.exception.ExceptionMessage; import alluxio.exception.ExceptionMessage;
import alluxio.exception.PreconditionMessage; import alluxio.exception.PreconditionMessage;
import alluxio.exception.status.UnavailableException; import alluxio.exception.status.AlluxioStatusException;
import alluxio.exception.status.ExceptionStatus;
import alluxio.retry.ExponentialBackoffRetry; import alluxio.retry.ExponentialBackoffRetry;
import alluxio.retry.RetryPolicy; import alluxio.retry.RetryPolicy;
import alluxio.security.authentication.TransportProvider; import alluxio.security.authentication.TransportProvider;
Expand Down Expand Up @@ -320,10 +321,12 @@ protected synchronized <V> V retryRPC(RpcCallable<V> rpc) throws IOException,
connect(); connect();
try { try {
return rpc.call(); return rpc.call();
} catch (UnavailableException e) {
throw new IOException(e);
} catch (AlluxioTException e) { } catch (AlluxioTException e) {
throw new RuntimeException(AlluxioException.fromThrift(e)); AlluxioStatusException se = AlluxioStatusException.fromThrift(e);
if (se.getStatus() == ExceptionStatus.UNAVAILABLE) {
throw new IOException(e);
}
throw se;
} catch (TException e) { } catch (TException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
disconnect(); disconnect();
Expand Down Expand Up @@ -356,9 +359,11 @@ protected synchronized <V> V retryRPC(RpcCallableThrowsAlluxioTException<V> rpc)
try { try {
return rpc.call(); return rpc.call();
} catch (AlluxioTException e) { } catch (AlluxioTException e) {
throw AlluxioException.fromThrift(e); AlluxioStatusException se = AlluxioStatusException.fromThrift(e);
} catch (UnavailableException e) { if (se.getStatus() == ExceptionStatus.UNAVAILABLE) {
throw new IOException(e); throw new IOException(e);
}
throw se;
} catch (TException e) { } catch (TException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
disconnect(); disconnect();
Expand Down
28 changes: 16 additions & 12 deletions core/common/src/main/java/alluxio/AbstractThriftClient.java
Expand Up @@ -12,7 +12,8 @@
package alluxio; package alluxio;


import alluxio.exception.AlluxioException; import alluxio.exception.AlluxioException;
import alluxio.exception.status.UnavailableException; import alluxio.exception.status.AlluxioStatusException;
import alluxio.exception.status.ExceptionStatus;
import alluxio.network.connection.ThriftClientPool; import alluxio.network.connection.ThriftClientPool;
import alluxio.retry.ExponentialBackoffRetry; import alluxio.retry.ExponentialBackoffRetry;
import alluxio.retry.RetryPolicy; import alluxio.retry.RetryPolicy;
Expand Down Expand Up @@ -106,16 +107,18 @@ protected <V> V retryRPC(RpcCallable<V, C> rpc) throws IOException {
C client = acquireClient(); C client = acquireClient();
try { try {
return rpc.call(client); return rpc.call(client);
} catch (UnavailableException e) {
throw new IOException(e);
} catch (AlluxioTException e) { } catch (AlluxioTException e) {
AlluxioException ae = AlluxioException.fromThrift(e); AlluxioStatusException se = AlluxioStatusException.fromThrift(e);
if (se.getStatus() == ExceptionStatus.UNAVAILABLE) {
throw new IOException(e);
}
try { try {
processException(client, ae); // TODO(andrew): figure out what's going on here and fix it
} catch (AlluxioException ee) { processException(client, se);
} catch (AlluxioStatusException ee) {
throw new IOException(ee); throw new IOException(ee);
} }
exception = new TException(ae); exception = new TException(se);
} catch (TException e) { } catch (TException e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());
closeClient(client); closeClient(client);
Expand Down Expand Up @@ -151,11 +154,12 @@ protected <V> V retryRPC(RpcCallableThrowsAlluxioTException<V, C> rpc)
try { try {
return rpc.call(client); return rpc.call(client);
} catch (AlluxioTException e) { } catch (AlluxioTException e) {
AlluxioException ae = AlluxioException.fromThrift(e); AlluxioStatusException se = AlluxioStatusException.fromThrift(e);
processException(client, ae); if (se.getStatus() == ExceptionStatus.UNAVAILABLE) {
exception = new TException(ae); throw new IOException(e);
} catch (UnavailableException e) { }
throw new IOException(e); processException(client, se);
exception = new TException(se);
} catch (TException e) { } catch (TException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
closeClient(client); closeClient(client);
Expand Down
115 changes: 0 additions & 115 deletions core/common/src/main/java/alluxio/exception/AlluxioException.java
Expand Up @@ -59,119 +59,4 @@ protected AlluxioException(String message) {
protected AlluxioException(String message, Throwable cause) { protected AlluxioException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }

/**
* Constructs a {@link AlluxioTException} from a {@link AlluxioException}.
*
* @return a {@link AlluxioTException} of the type of this exception
*/
public AlluxioTException toThrift() {
return new AlluxioTException(AlluxioExceptionType.getAlluxioExceptionType(getClass()),
getMessage(), getClass().getName());
}

/**
* Converts an Alluxio exception from Thrift representation to native representation.
*
* @param e the Alluxio Thrift exception
* @return the native Alluxio exception
*/
public static AlluxioException fromThrift(AlluxioTException e) {
Class<? extends AlluxioException> throwClass;
if (e.isSetClassName()) {
// server version 1.1.0 or newer
try {
throwClass = (Class<? extends AlluxioException>) Class.forName(e.getClassName());
} catch (ClassNotFoundException ee) {
// this can happen when the client is talking to a newer version of a server that
// introduced an exception that the client does not recognize
return new AlluxioException(e.getMessage());
}
} else {
// server version 1.0.x
throwClass = AlluxioExceptionType.getAlluxioExceptionClass(e.getType());
if (throwClass == null) {
return new AlluxioException(e.getMessage());
}
}
try {
return throwClass.getConstructor(String.class).newInstance(e.getMessage());
} catch (ReflectiveOperationException ee) {
String errorMessage = String
.format("Could not instantiate %s with a String-only constructor: %s", e.getType(),
ee.getMessage());
throw new IllegalStateException(errorMessage, ee);
}
}

/**
* Holds the different types of exceptions thrown by Alluxio.
*
* @deprecated since version 1.1 and will be removed in version 2.0
*/
@ThreadSafe
@Deprecated
private enum AlluxioExceptionType {
ACCESS_CONTROL(AccessControlException.class),
BLOCK_ALREADY_EXISTS(BlockAlreadyExistsException.class),
BLOCK_DOES_NOT_EXIST(BlockDoesNotExistException.class),
BLOCK_INFO(BlockInfoException.class),
CONNECTION_FAILED(ConnectionFailedException.class),
DEPENDENCY_DOES_NOT_EXIST(DependencyDoesNotExistException.class),
DIRECTORY_NOT_EMPTY_EXCEPTION(DirectoryNotEmptyException.class),
FAILED_TO_CHECKPOINT(FailedToCheckpointException.class),
FILE_ALREADY_COMPLETED(FileAlreadyCompletedException.class),
FILE_ALREADY_EXISTS(FileAlreadyExistsException.class),
FILE_DOES_NOT_EXIST(FileDoesNotExistException.class),
INVALID_FILE_SIZE(InvalidFileSizeException.class),
INVALID_PATH(InvalidPathException.class),
INVALID_WORKER_STATE(InvalidWorkerStateException.class),
LINEAGE_DELETION(LineageDeletionException.class),
LINEAGE_DOES_NOT_EXIST(LineageDoesNotExistException.class),
NO_WORKER(NoWorkerException.class),
WORKER_OUT_OF_SPACE(WorkerOutOfSpaceException.class);

private final Class<? extends AlluxioException> mExceptionClass;

/**
* Constructs a {@link AlluxioExceptionType} with its corresponding {@link AlluxioException}.
*/
AlluxioExceptionType(Class<? extends AlluxioException> exceptionClass) {
mExceptionClass = exceptionClass;
}

/**
* Produces an Alluxio exception whose type matches the given name.
*
* @param text the type name
* @return the Alluxio exception
*/
static Class<? extends AlluxioException> getAlluxioExceptionClass(String text) {
if (text != null) {
for (AlluxioExceptionType t : AlluxioExceptionType.values()) {
if (text.equalsIgnoreCase(t.name())) {
return t.mExceptionClass;
}
}
}
return null;
}

/**
* Produces the type name for the type that matches the given Alluxio exception.
*
* @param e the Alluxio exception
* @return the type name
*/
static String getAlluxioExceptionType(Class<? extends AlluxioException> e) {
if (e != null) {
for (AlluxioExceptionType t : AlluxioExceptionType.values()) {
if (t.mExceptionClass.equals(e)) {
return t.name();
}
}
}
return null;
}
}
} }
Expand Up @@ -31,6 +31,7 @@
import alluxio.exception.NoWorkerException; import alluxio.exception.NoWorkerException;
import alluxio.exception.UfsBlockAccessTokenUnavailableException; import alluxio.exception.UfsBlockAccessTokenUnavailableException;
import alluxio.exception.WorkerOutOfSpaceException; import alluxio.exception.WorkerOutOfSpaceException;
import alluxio.thrift.AlluxioTException;


import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
Expand Down Expand Up @@ -83,6 +84,57 @@ public ExceptionStatus getStatus() {
return mStatus; return mStatus;
} }


/**
* @return the Thrift representation of this exception
*/
public AlluxioTException toThrift() {
return new AlluxioTException(getMessage(), ExceptionStatus.toThrift(mStatus));
}

/**
* Converts an Alluxio exception from Thrift representation to native representation.
*
* @param e the Alluxio Thrift exception
* @return the native Alluxio exception
*/
public static AlluxioStatusException fromThrift(AlluxioTException e) {
String m = e.getMessage();
switch (e.getStatus()) {
case CANCELED:
return new CanceledException(m);
case INVALID_ARGUMENT:
return new InvalidArgumentException(m);
case DEADLINE_EXCEEDED:
return new DeadlineExceededException(m);
case NOT_FOUND:
return new NotFoundException(m);
case ALREADY_EXISTS:
return new AlreadyExistsException(m);
case PERMISSION_DENIED:
return new PermissionDeniedException(m);
case UNAUTHENTICATED:
return new UnauthenticatedException(m);
case RESOURCE_EXHAUSTED:
return new ResourceExhaustedException(m);
case FAILED_PRECONDITION:
return new FailedPreconditionException(m);
case ABORTED:
return new AbortedException(m);
case OUT_OF_RANGE:
return new OutOfRangeException(m);
case UNIMPLEMENTED:
return new UnimplementedException(m);
case INTERNAL:
return new InternalException(m);
case UNAVAILABLE:
return new UnavailableException(m);
case DATA_LOSS:
return new DataLossException(m);
default:
return new UnknownException(m);
}
}

/** /**
* Converts checked Alluxio exceptions to Alluxio status exceptions. * Converts checked Alluxio exceptions to Alluxio status exceptions.
* *
Expand Down

0 comments on commit de265e0

Please sign in to comment.