BlockManagerMaster源码分析
- BlockManagerMaster运行在driver上
- BlockManagerMaster使用BlockManagerMasterEndpoint允许executors发送块状态更新消息并且能够跟踪这些消息。说穿了,就是负责对各个节点上的BlockManager内部管理的数据的元数据,进行维护。比如block增删改等操作,都会在这里维护数据的变更。
1. SparkEnv实例化一个BlockManagerMaster对象
val blockManagerMaster = new BlockManagerMaster(
registerOrLookupEndpoint(
BlockManagerMaster.DRIVER_ENDPOINT_NAME,
new BlockManagerMasterEndpoint(rpcEnv, isLocal, conf, listenerBus)),
conf,
isDriver)
进入registerOrLookupEndpoint方法
def registerOrLookupEndpoint(
name: String, endpointCreator: => RpcEndpoint):
RpcEndpointRef = {
if (isDriver) {
logInfo("Registering " + name)
rpcEnv.setupEndpoint(name, endpointCreator)
} else {
RpcUtils.makeDriverRef(name, conf, rpcEnv)
}
}
如果是river端,就在BlockManagerMaster内部,创建终端点BlockManagerMasterEndpoint,并进行注册,最终调用代码如下:
def registerRpcEndpoint(name: String, endpoint: RpcEndpoint): NettyRpcEndpointRef = {
val addr = RpcEndpointAddress(nettyEnv.address, name)
val endpointRef = new NettyRpcEndpointRef(nettyEnv.conf, addr, nettyEnv)
synchronized {
if (stopped) {
throw new IllegalStateException("RpcEnv has been stopped")
}
if (endpoints.putIfAbsent(name, new EndpointData(name, endpoint, endpointRef)) != null) {
throw new IllegalArgumentException(s"There is already an RpcEndpoint called $name")
}
val data = endpoints.get(name)
endpointRefs.put(data.endpoint, data.ref)
receivers.offer(data) // for the OnStart message
}
endpointRef
}
如果是executor,则创建BlockManagerMasterEndpoint的引用