-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-20529][Core]Allow worker and master work with a proxy server #17821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,20 @@ private[deploy] class Worker( | |
|
|
||
| private val testing: Boolean = sys.props.contains("spark.testing") | ||
| private var master: Option[RpcEndpointRef] = None | ||
|
|
||
| /** | ||
| * Whether to use the master address in `masterRpcAddresses` if possible. If it's disabled, Worker | ||
| * will just use the address received from Master. | ||
| */ | ||
| private val preferConfiguredMasterAddress = | ||
| conf.getBoolean("spark.worker.preferConfiguredMasterAddress", false) | ||
| /** | ||
| * The master address to connect in case of failure. When the connection is broken, worker will | ||
| * use this address to connect. This is usually just one of `masterRpcAddresses`. However, when | ||
| * a master is restarted or takes over leadership, it will be an address sent from master, which | ||
| * may not be in `masterRpcAddresses`. | ||
| */ | ||
| private var masterAddressToConnect: Option[RpcAddress] = None | ||
| private var activeMasterUrl: String = "" | ||
| private[worker] var activeMasterWebUiUrl : String = "" | ||
| private var workerWebUiUrl: String = "" | ||
|
|
@@ -196,10 +210,19 @@ private[deploy] class Worker( | |
| metricsSystem.getServletHandlers.foreach(webUi.attachHandler) | ||
| } | ||
|
|
||
| private def changeMaster(masterRef: RpcEndpointRef, uiUrl: String) { | ||
| /** | ||
| * Change to use the new master. | ||
| * | ||
| * @param masterRef the new master ref | ||
| * @param uiUrl the new master Web UI address | ||
| * @param masterAddress the new master address which the worker should use to connect in case of | ||
| * failure | ||
| */ | ||
| private def changeMaster(masterRef: RpcEndpointRef, uiUrl: String, masterAddress: RpcAddress) { | ||
| // activeMasterUrl it's a valid Spark url since we receive it from master. | ||
| activeMasterUrl = masterRef.address.toSparkURL | ||
| activeMasterWebUiUrl = uiUrl | ||
| masterAddressToConnect = Some(masterAddress) | ||
| master = Some(masterRef) | ||
| connected = true | ||
| if (conf.getBoolean("spark.ui.reverseProxy", false)) { | ||
|
|
@@ -266,7 +289,8 @@ private[deploy] class Worker( | |
| if (registerMasterFutures != null) { | ||
| registerMasterFutures.foreach(_.cancel(true)) | ||
| } | ||
| val masterAddress = masterRef.address | ||
| val masterAddress = | ||
| if (preferConfiguredMasterAddress) masterAddressToConnect.get else masterRef.address | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it isn't an issue but do you think we should fall back to val masterAddress = masterAddressToConnect match {
case Some(master) if preferConfiguredMasterAddress => master
case _ => masterRef.address
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now |
||
| registerMasterFutures = Array(registerMasterThreadPool.submit(new Runnable { | ||
| override def run(): Unit = { | ||
| try { | ||
|
|
@@ -342,15 +366,27 @@ private[deploy] class Worker( | |
| } | ||
|
|
||
| private def sendRegisterMessageToMaster(masterEndpoint: RpcEndpointRef): Unit = { | ||
| masterEndpoint.send(RegisterWorker(workerId, host, port, self, cores, memory, workerWebUiUrl)) | ||
| masterEndpoint.send(RegisterWorker( | ||
| workerId, | ||
| host, | ||
| port, | ||
| self, | ||
| cores, | ||
| memory, | ||
| workerWebUiUrl, | ||
| masterEndpoint.address)) | ||
| } | ||
|
|
||
| private def handleRegisterResponse(msg: RegisterWorkerResponse): Unit = synchronized { | ||
| msg match { | ||
| case RegisteredWorker(masterRef, masterWebUiUrl) => | ||
| logInfo("Successfully registered with master " + masterRef.address.toSparkURL) | ||
| case RegisteredWorker(masterRef, masterWebUiUrl, masterAddress) => | ||
| if (preferConfiguredMasterAddress) { | ||
| logInfo("Successfully registered with master " + masterAddress.toSparkURL) | ||
| } else { | ||
| logInfo("Successfully registered with master " + masterRef.address.toSparkURL) | ||
| } | ||
| registered = true | ||
| changeMaster(masterRef, masterWebUiUrl) | ||
| changeMaster(masterRef, masterWebUiUrl, masterAddress) | ||
| forwordMessageScheduler.scheduleAtFixedRate(new Runnable { | ||
| override def run(): Unit = Utils.tryLogNonFatalError { | ||
| self.send(SendHeartbeat) | ||
|
|
@@ -419,7 +455,7 @@ private[deploy] class Worker( | |
|
|
||
| case MasterChanged(masterRef, masterWebUiUrl) => | ||
| logInfo("Master has changed, new master is at " + masterRef.address.toSparkURL) | ||
| changeMaster(masterRef, masterWebUiUrl) | ||
| changeMaster(masterRef, masterWebUiUrl, masterRef.address) | ||
|
|
||
| val execs = executors.values. | ||
| map(e => new ExecutorDescription(e.appId, e.execId, e.cores, e.state)) | ||
|
|
@@ -561,7 +597,8 @@ private[deploy] class Worker( | |
| } | ||
|
|
||
| override def onDisconnected(remoteAddress: RpcAddress): Unit = { | ||
| if (master.exists(_.address == remoteAddress)) { | ||
| if (master.exists(_.address == remoteAddress) || | ||
| masterAddressToConnect.exists(_ == remoteAddress)) { | ||
| logInfo(s"$remoteAddress Disassociated !") | ||
| masterDisconnected() | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid adding an extra field here? Perhaps just put the
masterAddressin themasterfield.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked the current codes. Unfortunately, we cannot remove this extra field.
master.addressandmasterAddressare different.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, that sounds good.