From d16e2fdd712bf7a53120ab826cee8ff78e8cbf0f Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Thu, 12 Jan 2012 06:47:29 +0000 Subject: [PATCH] svn merge -c 1212004 from trunk for HADOOP-7897. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23-PB@1230416 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/ipc/ProtobufHelper.java | 15 ++++++----- .../apache/hadoop/ipc/ProtobufRpcEngine.java | 26 +++++++------------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 2ec8c9d72e2..9a063da07bf 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -37,6 +37,9 @@ Release 0.23-PB - Unreleased HADOOP-7833. Fix findbugs warnings in protobuf generated code. (John Lee via suresh) + HADOOP-7897. ProtobufRpcEngine client side exception mechanism is not + consistent with WritableRpcEngine. (suresh) + Release 0.23.1 - Unreleased INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufHelper.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufHelper.java index 7f029618fa4..e30f28a698a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufHelper.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufHelper.java @@ -33,14 +33,17 @@ private ProtobufHelper() { } /** - * Return the RemoteException wrapped in ServiceException as cause. - * @param se ServiceException that wraps RemoteException - * @return RemoteException wrapped in ServiceException or - * a new IOException that wraps unexpected ServiceException. + * Return the IOException thrown by the remote server wrapped in + * ServiceException as cause. + * @param se ServiceException that wraps IO exception thrown by the server + * @return Exception wrapped in ServiceException or + * a new IOException that wraps the unexpected ServiceException. */ public static IOException getRemoteException(ServiceException se) { Throwable e = se.getCause(); - return ((e instanceof RemoteException) ? (IOException) e : - new IOException(se)); + if (e == null) { + return new IOException(se); + } + return e instanceof IOException ? (IOException) e : new IOException(se); } } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java index 3db73859e58..637d3d9835e 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine.java @@ -144,9 +144,10 @@ private HadoopRpcRequestProto constructRpcRequest(Method method, * * ServiceException has the following causes: *
    - *
  1. Exceptions encountered in this methods are thrown as - * RpcClientException, wrapped in RemoteException
  2. - *
  3. Remote exceptions are thrown wrapped in RemoteException
  4. + *
  5. Exceptions encountered on the client side in this method are + * set as cause in ServiceException as is.
  6. + *
  7. Exceptions from the server are wrapped in RemoteException and are + * set as cause in ServiceException
  8. *
* * Note that the client calling protobuf RPC methods, must handle @@ -167,9 +168,8 @@ public Object invoke(Object proxy, Method method, Object[] args) try { val = (RpcResponseWritable) client.call(RpcKind.RPC_PROTOCOL_BUFFER, new RpcRequestWritable(rpcRequest), remoteId); - } catch (Exception e) { - RpcClientException ce = new RpcClientException("Client exception", e); - throw new ServiceException(getRemoteException(ce)); + } catch (Throwable e) { + throw new ServiceException(e); } HadoopRpcResponseProto response = val.message; @@ -197,9 +197,8 @@ public Object invoke(Object proxy, Method method, Object[] args) try { returnMessage = prototype.newBuilderForType() .mergeFrom(response.getResponse()).build(); - } catch (InvalidProtocolBufferException e) { - RpcClientException ce = new RpcClientException("Client exception", e); - throw new ServiceException(getRemoteException(ce)); + } catch (Throwable e) { + throw new ServiceException(e); } return returnMessage; } @@ -309,11 +308,6 @@ public RPC.Server getServer(Class protocol, Object protocolImpl, numHandlers, numReaders, queueSizePerHandler, verbose, secretManager); } - private static RemoteException getRemoteException(Exception e) { - return new RemoteException(e.getClass().getName(), - StringUtils.stringifyException(e)); - } - public static class Server extends RPC.Server { /** * Construct an RPC server. @@ -335,8 +329,8 @@ public Server(Class protocolClass, Object protocolImpl, numReaders, queueSizePerHandler, conf, classNameBase(protocolImpl .getClass().getName()), secretManager); this.verbose = verbose; - registerProtocolAndImpl(RpcKind.RPC_PROTOCOL_BUFFER, - protocolClass, protocolImpl); + registerProtocolAndImpl(RpcKind.RPC_PROTOCOL_BUFFER, protocolClass, + protocolImpl); } private static RpcResponseWritable handleException(Throwable e) {