diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcClient.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcClient.java index 2996357b90..563f3d0864 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcClient.java @@ -432,8 +432,11 @@ private Object invokeMethod( 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 @@ private Object invoke(String nsId, int retryCount, final Method method, throw new StandbyException(ioe.getMessage()); } } else { - if (ioe instanceof RemoteException) { - RemoteException re = (RemoteException) ioe; - ioe = re.unwrapRemoteException(); - ioe = getCleanException(ioe); - } throw ioe; } } else { diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java index 687e57839d..30a47a4562 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcMultiDestination.java @@ -188,6 +188,31 @@ private void testListing(String path) throws IOException { 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 {