[hadoop] 02/50: HDFS-12977. [SBN read] Add stateId to RPC headers. Contributed by Plamen Jeliazkov.

2019-07-25 Thread cliang
This is an automated email from the ASF dual-hosted git repository.

cliang pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/hadoop.git

commit ccad9ce59bb85c4ec5adcad10bb77e2172f2b1ad
Author: Plamen Jeliazkov 
AuthorDate: Tue Mar 20 18:48:40 2018 -0700

HDFS-12977. [SBN read] Add stateId to RPC headers. Contributed by Plamen 
Jeliazkov.
---
 .../org/apache/hadoop/ipc/AlignmentContext.java|  51 
 .../main/java/org/apache/hadoop/ipc/Client.java|   9 ++
 .../org/apache/hadoop/ipc/ProtobufRpcEngine.java   |   9 +-
 .../src/main/java/org/apache/hadoop/ipc/RPC.java   |  10 +-
 .../main/java/org/apache/hadoop/ipc/RpcEngine.java |   5 +-
 .../main/java/org/apache/hadoop/ipc/Server.java|  21 +++-
 .../org/apache/hadoop/ipc/WritableRpcEngine.java   |  33 +-
 .../hadoop-common/src/main/proto/RpcHeader.proto   |   1 +
 .../test/java/org/apache/hadoop/ipc/TestRPC.java   |   3 +-
 .../org/apache/hadoop/hdfs/ClientGCIContext.java   |  65 ++
 .../java/org/apache/hadoop/hdfs/DFSClient.java |   3 +
 .../hdfs/server/namenode/GlobalStateIdContext.java |  59 ++
 .../hdfs/server/namenode/NameNodeRpcServer.java|   1 +
 .../hadoop/hdfs/TestStateAlignmentContext.java | 131 +
 14 files changed, 389 insertions(+), 12 deletions(-)

diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/AlignmentContext.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/AlignmentContext.java
new file mode 100644
index 000..f952325
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/AlignmentContext.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ipc;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto;
+
+/**
+ * This interface intends to align the state between client and server
+ * via RPC communication.
+ *
+ * This should be implemented separately on the client side and server side
+ * and can be used to pass state information on RPC responses from server
+ * to client.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Stable
+public interface AlignmentContext {
+
+  /**
+   * This is the intended server method call to implement to pass state info
+   * during RPC response header construction.
+   * @param header The RPC response header builder.
+   */
+  void updateResponseState(RpcResponseHeaderProto.Builder header);
+
+  /**
+   * This is the intended client method call to implement to recieve state info
+   * during RPC response processing.
+   * @param header The RPC response header.
+   */
+  void receiveResponseState(RpcResponseHeaderProto header);
+
+}
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 9ee0647..bb09799 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
@@ -103,6 +103,12 @@ public class Client implements AutoCloseable {
   return false;
 }
   };
+  private static AlignmentContext alignmentContext;
+
+  /** Set alignment context to use to fetch state alignment info from RPC. */
+  public static void setAlignmentContext(AlignmentContext ac) {
+alignmentContext = ac;
+  }
 
   @SuppressWarnings("unchecked")
   @Unstable
@@ -1184,6 +1190,9 @@ public class Client implements AutoCloseable {
   final Call call = calls.remove(callId);
   call.setRpcResponse(value);
 }
+if (alignmentContext != null) {
+  alignmentContext.receiveResponseState(header);
+}
 // verify that packet length was correct
 if (packet.remaining() > 0) {
   throw new RpcClientException("RPC response length mismatch");
diff --git 

[hadoop] 02/50: HDFS-12977. [SBN read] Add stateId to RPC headers. Contributed by Plamen Jeliazkov.

2019-06-28 Thread cliang
This is an automated email from the ASF dual-hosted git repository.

cliang pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/hadoop.git

commit 1eeca2d9fb7c587b2bfbdb630e35b0ca8b27014a
Author: Plamen Jeliazkov 
AuthorDate: Tue Mar 20 18:48:40 2018 -0700

HDFS-12977. [SBN read] Add stateId to RPC headers. Contributed by Plamen 
Jeliazkov.
---
 .../org/apache/hadoop/ipc/AlignmentContext.java|  51 
 .../main/java/org/apache/hadoop/ipc/Client.java|   9 ++
 .../org/apache/hadoop/ipc/ProtobufRpcEngine.java   |   9 +-
 .../src/main/java/org/apache/hadoop/ipc/RPC.java   |  10 +-
 .../main/java/org/apache/hadoop/ipc/RpcEngine.java |   5 +-
 .../main/java/org/apache/hadoop/ipc/Server.java|  15 ++-
 .../org/apache/hadoop/ipc/WritableRpcEngine.java   |  33 +-
 .../hadoop-common/src/main/proto/RpcHeader.proto   |   1 +
 .../test/java/org/apache/hadoop/ipc/TestRPC.java   |   3 +-
 .../org/apache/hadoop/hdfs/ClientGCIContext.java   |  65 ++
 .../java/org/apache/hadoop/hdfs/DFSClient.java |   3 +
 .../hdfs/server/namenode/GlobalStateIdContext.java |  59 ++
 .../hdfs/server/namenode/NameNodeRpcServer.java|   1 +
 .../hadoop/hdfs/TestStateAlignmentContext.java | 131 +
 14 files changed, 383 insertions(+), 12 deletions(-)

diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/AlignmentContext.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/AlignmentContext.java
new file mode 100644
index 000..f952325
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/AlignmentContext.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ipc;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto;
+
+/**
+ * This interface intends to align the state between client and server
+ * via RPC communication.
+ *
+ * This should be implemented separately on the client side and server side
+ * and can be used to pass state information on RPC responses from server
+ * to client.
+ */
+@InterfaceAudience.Private
+@InterfaceStability.Stable
+public interface AlignmentContext {
+
+  /**
+   * This is the intended server method call to implement to pass state info
+   * during RPC response header construction.
+   * @param header The RPC response header builder.
+   */
+  void updateResponseState(RpcResponseHeaderProto.Builder header);
+
+  /**
+   * This is the intended client method call to implement to recieve state info
+   * during RPC response processing.
+   * @param header The RPC response header.
+   */
+  void receiveResponseState(RpcResponseHeaderProto header);
+
+}
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 c6ac732..096c164 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
@@ -103,6 +103,12 @@ public class Client implements AutoCloseable {
   return false;
 }
   };
+  private static AlignmentContext alignmentContext;
+
+  /** Set alignment context to use to fetch state alignment info from RPC. */
+  public static void setAlignmentContext(AlignmentContext ac) {
+alignmentContext = ac;
+  }
 
   @SuppressWarnings("unchecked")
   @Unstable
@@ -1186,6 +1192,9 @@ public class Client implements AutoCloseable {
   final Call call = calls.remove(callId);
   call.setRpcResponse(value);
 }
+if (alignmentContext != null) {
+  alignmentContext.receiveResponseState(header);
+}
 // verify that packet length was correct
 if (packet.remaining() > 0) {
   throw new RpcClientException("RPC response length mismatch");
diff --git