From 02c99f3748edef2835111fa31bbde89f3544edb7 Mon Sep 17 00:00:00 2001 From: Sanjay Radia Date: Thu, 16 May 2013 01:32:14 +0000 Subject: [PATCH] Merged HADOOP-9151 git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1483144 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../dev-support/findbugsExcludeFile.xml | 7 ++++ .../java/org/apache/hadoop/ipc/Client.java | 32 +++++++++++-------- .../java/org/apache/hadoop/ipc/Server.java | 10 +++--- .../src/main/proto/RpcHeader.proto | 13 ++++---- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 7c85401768d..42c771b4601 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -7,6 +7,9 @@ Release 2.0.5-beta - UNRELEASED HADOOP-9163 The rpc msg in ProtobufRpcEngine.proto should be moved out to avoid an extra copy (Sanjay Radia) + HADOOP-9151 Include RPC error info in RpcResponseHeader instead of sending + it separately (sanjay Radia) + NEW FEATURES HADOOP-9194. RPC support for QoS. (Junping Du via llu) diff --git a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml index be4506f928d..18469981266 100644 --- a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml +++ b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml @@ -320,4 +320,11 @@ + + + + + + + diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java index 54d2d78191e..04709d417d7 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java @@ -59,7 +59,6 @@ import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.Writable; -import org.apache.hadoop.io.WritableUtils; import org.apache.hadoop.io.retry.RetryPolicies; import org.apache.hadoop.io.retry.RetryPolicy; import org.apache.hadoop.io.retry.RetryPolicy.RetryAction; @@ -942,31 +941,38 @@ public class Client { touch(); try { - RpcResponseHeaderProto response = + RpcResponseHeaderProto header = RpcResponseHeaderProto.parseDelimitedFrom(in); - if (response == null) { + if (header == null) { throw new IOException("Response is null."); } - int callId = response.getCallId(); + int callId = header.getCallId(); if (LOG.isDebugEnabled()) LOG.debug(getName() + " got value #" + callId); Call call = calls.get(callId); - RpcStatusProto status = response.getStatus(); + RpcStatusProto status = header.getStatus(); if (status == RpcStatusProto.SUCCESS) { Writable value = ReflectionUtils.newInstance(valueClass, conf); value.readFields(in); // read value call.setRpcResponse(value); calls.remove(callId); - } else if (status == RpcStatusProto.ERROR) { - call.setException(new RemoteException(WritableUtils.readString(in), - WritableUtils.readString(in))); - calls.remove(callId); - } else if (status == RpcStatusProto.FATAL) { - // Close the connection - markClosed(new RemoteException(WritableUtils.readString(in), - WritableUtils.readString(in))); + } else { // Rpc Request failed + final String exceptionClassName = header.hasExceptionClassName() ? + header.getExceptionClassName() : + "ServerDidNotSetExceptionClassName"; + final String errorMsg = header.hasErrorMsg() ? + header.getErrorMsg() : "ServerDidNotSetErrorMsg" ; + RemoteException re = + new RemoteException(exceptionClassName, errorMsg); + if (status == RpcStatusProto.ERROR) { + call.setException(re); + calls.remove(callId); + } else if (status == RpcStatusProto.FATAL) { + // Close the connection + markClosed(re); + } } } catch (IOException e) { markClosed(e); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java index 60c7c5dbb44..1731286757c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java @@ -2024,6 +2024,7 @@ public abstract class Server { RpcResponseHeaderProto.newBuilder(); response.setCallId(call.callId); response.setStatus(status); + response.setServerIpcVersionNum(Server.CURRENT_VERSION); if (status == RpcStatusProto.SUCCESS) { @@ -2040,13 +2041,10 @@ public abstract class Server { StringUtils.stringifyException(t)); return; } - } else { - if (status == RpcStatusProto.FATAL) { - response.setServerIpcVersionNum(Server.CURRENT_VERSION); - } + } else { // Rpc Failure + response.setExceptionClassName(errorClass); + response.setErrorMsg(error); response.build().writeDelimitedTo(out); - WritableUtils.writeString(out, errorClass); - WritableUtils.writeString(out, error); } if (call.connection.useWrap) { wrapWithSasl(responseBuf, call); diff --git a/hadoop-common-project/hadoop-common/src/main/proto/RpcHeader.proto b/hadoop-common-project/hadoop-common/src/main/proto/RpcHeader.proto index 723434bf2fe..82bd4cbc850 100644 --- a/hadoop-common-project/hadoop-common/src/main/proto/RpcHeader.proto +++ b/hadoop-common-project/hadoop-common/src/main/proto/RpcHeader.proto @@ -70,12 +70,11 @@ message RpcRequestHeaderProto { // the header for the RpcRequest * | RpcResponseHeaderProto - serialized delimited ie has len | * +------------------------------------------------------------------+ * | if request is successful: | - * | - RpcResponse - The actual rpc response bytes | - * | This response is serialized based on RpcKindProto | + * | - RpcResponse - The actual rpc response bytes follow | + * the response header | + * | This response is serialized based on RpcKindProto | * | if request fails : | - * | - length (4 byte int) + Class name of exception - UTF-8 string | - * | - length (4 byte int) + Stacktrace - UTF-8 string | - * | if the strings are null then the length is -1 | + * | The rpc response header contains the necessary info | * +------------------------------------------------------------------+ * */ @@ -88,5 +87,7 @@ message RpcResponseHeaderProto { required uint32 callId = 1; // callId used in Request required RpcStatusProto status = 2; - optional uint32 serverIpcVersionNum = 3; // in case of an fatal IPC error + optional uint32 serverIpcVersionNum = 3; // Sent if success or fail + optional string exceptionClassName = 4; // if request fails + optional string errorMsg = 5; // if request fails, often contains strack trace }