引言
我们知道,jobmanager和taskmanager在集群模式下,是部署在不同机器上面的,那么现在就有一个问题,jobmanager和taskmanager是如何相互调用的。
分析
切入点
1 考虑以taskExecutor方法的submitTask方法为入口,查看调用关系
图中并没有提供明显的线索,看RpcTaskManagerGateway所处的包,猜测其位于JobManager,然后突然调用到了TaskManager,很是困惑。
2 在submitTask中增加断点,获得调用堆栈
3.在org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway.submitTask(TaskDeploymentDescriptor, Time)中增加断点
结论
经过上面的分析,flink中的rpc已经相当清楚了
客户端
客户端被AkkaInvocationHandler代理,调用下面方法
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Class<?> declaringClass = method.getDeclaringClass();
Object result;
if (declaringClass.equals(AkkaBasedEndpoint.class) ||
declaringClass.equals(Object.class) ||
declaringClass.equals(RpcGateway.class) ||
declaringClass.equals(StartStoppable.class) ||
declaringClass.equals(MainThreadExecutable.class) ||
declaringClass.equals(RpcServer.class)) {
result = method.invoke(this, args);
} else if (declaringClass.equals(FencedRpcGateway.class)) {
throw new UnsupportedOperationException("AkkaInvocationHandler does not support the call FencedRpcGateway#" +
method.getName() + ". This indicates that you retrieved a FencedRpcGateway without specifying a " +
"fencing token. Please use RpcService#connect(RpcService, F, Time) with F being the fencing token to " +
"retrieve a properly FencedRpcGateway.");
} else {
//代理的方法
result = invokeRpc(method