spark源码分析--Master和worker建立连接
原创,转载请注明出处。作者邮箱 vc_java@hotmail.com
Spark的master启动后,等待work通过spark://master'ip:7077的url去连接Master.
在worker的回调函数preStart(Worker.scala)里面,调用了函数connectToMaster,这个函数完成了向Master节点注册work的工作。执行的方法是向master发送一个RegisterWorker消息
master ! RegisterWorker(workerId, host, port, cores, memory, webUi.boundPort.get, publicAddress)
case RegisterWorker(id, host, workerPort, cores, memory, worker_webUiPort, publicAddress) => { ........ if (idToWorker.contains(id)) { sender ! RegisterWorkerFailed("Duplicate worker ID") } else {//如果idToWorker里面没有,成功注册 addWorker(id, host, workerPort, cores, memory, worker_webUiPort, publicAddress) ........ sender ! RegisteredWorker("http://" + masterPublicAddress + ":" + webUi.boundPort.get) schedule() } } case RegisteredWorker(url) => ....... context.system.scheduler.schedule(0 millis, HEARTBEAT_MILLIS millis) { master ! Heartbeat(workerId) }