|
@@ -18,6 +18,8 @@
|
|
|
|
|
|
package org.apache.hadoop.hdfs.server.federation.router;
|
|
|
|
|
|
+import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_CALLER_CONTEXT_SEPARATOR_DEFAULT;
|
|
|
+import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_CALLER_CONTEXT_SEPARATOR_KEY;
|
|
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_KEY;
|
|
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_TIMEOUT_KEY;
|
|
|
|
|
@@ -66,8 +68,10 @@ import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
|
|
|
import org.apache.hadoop.io.retry.RetryPolicies;
|
|
|
import org.apache.hadoop.io.retry.RetryPolicy;
|
|
|
import org.apache.hadoop.io.retry.RetryPolicy.RetryAction.RetryDecision;
|
|
|
+import org.apache.hadoop.ipc.CallerContext;
|
|
|
import org.apache.hadoop.ipc.RemoteException;
|
|
|
import org.apache.hadoop.ipc.RetriableException;
|
|
|
+import org.apache.hadoop.ipc.Server;
|
|
|
import org.apache.hadoop.ipc.StandbyException;
|
|
|
import org.apache.hadoop.net.ConnectTimeoutException;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
@@ -115,11 +119,14 @@ public class RouterRpcClient {
|
|
|
private final RetryPolicy retryPolicy;
|
|
|
/** Optional perf monitor. */
|
|
|
private final RouterRpcMonitor rpcMonitor;
|
|
|
+ /** Field separator of CallerContext. */
|
|
|
+ private final String contextFieldSeparator;
|
|
|
|
|
|
/** Pattern to parse a stack trace line. */
|
|
|
private static final Pattern STACK_TRACE_PATTERN =
|
|
|
Pattern.compile("\\tat (.*)\\.(.*)\\((.*):(\\d*)\\)");
|
|
|
|
|
|
+ private static final String CLIENT_IP_STR = "clientIp";
|
|
|
|
|
|
/**
|
|
|
* Create a router RPC client to manage remote procedure calls to NNs.
|
|
@@ -136,6 +143,9 @@ public class RouterRpcClient {
|
|
|
this.namenodeResolver = resolver;
|
|
|
|
|
|
Configuration clientConf = getClientConfiguration(conf);
|
|
|
+ this.contextFieldSeparator =
|
|
|
+ clientConf.get(HADOOP_CALLER_CONTEXT_SEPARATOR_KEY,
|
|
|
+ HADOOP_CALLER_CONTEXT_SEPARATOR_DEFAULT);
|
|
|
this.connectionManager = new ConnectionManager(clientConf);
|
|
|
this.connectionManager.start();
|
|
|
|
|
@@ -404,6 +414,7 @@ public class RouterRpcClient {
|
|
|
" with params " + Arrays.deepToString(params) + " from "
|
|
|
+ router.getRouterId());
|
|
|
}
|
|
|
+ appendClientIpToCallerContext();
|
|
|
|
|
|
Object ret = null;
|
|
|
if (rpcMonitor != null) {
|
|
@@ -519,6 +530,20 @@ public class RouterRpcClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * For Tracking which is the actual client address.
|
|
|
+ * It adds key/value (clientIp/"ip") pair to the caller context.
|
|
|
+ */
|
|
|
+ private void appendClientIpToCallerContext() {
|
|
|
+ final CallerContext ctx = CallerContext.getCurrent();
|
|
|
+ String origContext = ctx == null ? null : ctx.getContext();
|
|
|
+ byte[] origSignature = ctx == null ? null : ctx.getSignature();
|
|
|
+ CallerContext.setCurrent(
|
|
|
+ new CallerContext.Builder(origContext, contextFieldSeparator)
|
|
|
+ .append(CLIENT_IP_STR, Server.getRemoteAddress())
|
|
|
+ .setSignature(origSignature).build());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Invokes a method on the designated object. Catches exceptions specific to
|
|
|
* the invocation.
|