Browse Source

HDFS-14721. RBF: ProxyOpComplete is not accurate in FederationRPCPerformanceMonitor. Contributed by xuzq.

Ayush Saxena 5 năm trước cách đây
mục cha
commit
8e779a151e

+ 4 - 6
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcClient.java

@@ -432,8 +432,11 @@ public class RouterRpcClient {
           if (this.rpcMonitor != null) {
             this.rpcMonitor.proxyOpComplete(true);
           }
+          RemoteException re = (RemoteException) ioe;
+          ioe = re.unwrapRemoteException();
+          ioe = getCleanException(ioe);
           // RemoteException returned by NN
-          throw (RemoteException) ioe;
+          throw ioe;
         } else if (ioe instanceof ConnectionNullException) {
           if (this.rpcMonitor != null) {
             this.rpcMonitor.proxyOpFailureCommunicate();
@@ -553,11 +556,6 @@ public class RouterRpcClient {
             throw new StandbyException(ioe.getMessage());
           }
         } else {
-          if (ioe instanceof RemoteException) {
-            RemoteException re = (RemoteException) ioe;
-            ioe = re.unwrapRemoteException();
-            ioe = getCleanException(ioe);
-          }
           throw ioe;
         }
       } else {

+ 25 - 0
hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java

@@ -188,6 +188,31 @@ public class TestRouterRpcMultiDestination extends TestRouterRpc {
         requiredPaths.size(), partialListing.length);
   }
 
+  /**
+   * Verify the metric ProxyOp with RemoteException.
+   */
+  @Test
+  public void testProxyOpWithRemoteException() throws IOException {
+    final String testPath = "/proxy_op/remote_exception.txt";
+    final FederationRPCMetrics metrics = getRouterContext().
+        getRouter().getRpcServer().getRPCMetrics();
+    String ns1 = getCluster().getNameservices().get(1);
+    final FileSystem fileSystem1 = getCluster().
+        getNamenode(ns1, null).getFileSystem();
+
+    try {
+      // Create the test file in ns1.
+      createFile(fileSystem1, testPath, 32);
+
+      long beforeProxyOp = metrics.getProxyOps();
+      // First retry nn0 with remoteException then nn1.
+      getRouterProtocol().getBlockLocations(testPath, 0, 1);
+      assertEquals(2, metrics.getProxyOps() - beforeProxyOp);
+    } finally {
+      fileSystem1.delete(new Path(testPath), true);
+    }
+  }
+
   @Override
   public void testProxyListFiles() throws IOException, InterruptedException,
       URISyntaxException, NoSuchMethodException, SecurityException {