-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-26790][CORE] Change approach for retrieving executor logs and attributes: self-retrieve #23706
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
[SPARK-26790][CORE] Change approach for retrieving executor logs and attributes: self-retrieve #23706
Changes from 3 commits
a9579b5
6a3ef10
23d5432
cf44bb4
6970d50
7992091
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 |
|---|---|---|
|
|
@@ -65,7 +65,7 @@ private[spark] class CoarseGrainedExecutorBackend( | |
| }(ThreadUtils.sameThread).onComplete { | ||
| // This is a very fast action so we can use "ThreadUtils.sameThread" | ||
| case Success(msg) => | ||
| // Always receive `true`. Just ignore it | ||
| // Always receive `true`. Just ignore it | ||
| case Failure(e) => | ||
| exitExecutor(1, s"Cannot register with driver: $driverUrl", e, notifyDriver = false) | ||
| }(ThreadUtils.sameThread) | ||
|
|
@@ -181,14 +181,15 @@ private[spark] class CoarseGrainedExecutorBackend( | |
|
|
||
| private[spark] object CoarseGrainedExecutorBackend extends Logging { | ||
|
|
||
| private def run( | ||
| def run( | ||
| driverUrl: String, | ||
| executorId: String, | ||
| hostname: String, | ||
| cores: Int, | ||
| appId: String, | ||
| workerUrl: Option[String], | ||
| userClassPath: Seq[URL]) { | ||
| userClassPath: Seq[URL], | ||
|
Contributor
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. This is actually not used now. I'm almost suggesting you should just have
Contributor
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. Ah yes nice suggestion. I missed it. Will address. |
||
| backendCreateFn: (RpcEnv, SparkEnv) => CoarseGrainedExecutorBackend) { | ||
|
|
||
| Utils.initDaemon(log) | ||
|
|
||
|
|
@@ -228,8 +229,7 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging { | |
| val env = SparkEnv.createExecutorEnv( | ||
| driverConf, executorId, hostname, cores, cfg.ioEncryptionKey, isLocal = false) | ||
|
|
||
| env.rpcEnv.setupEndpoint("Executor", new CoarseGrainedExecutorBackend( | ||
| env.rpcEnv, driverUrl, executorId, hostname, cores, userClassPath, env)) | ||
| env.rpcEnv.setupEndpoint("Executor", backendCreateFn(env.rpcEnv, env)) | ||
| workerUrl.foreach { url => | ||
| env.rpcEnv.setupEndpoint("WorkerWatcher", new WorkerWatcher(env.rpcEnv, url)) | ||
| } | ||
|
|
@@ -285,25 +285,29 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging { | |
| printUsageAndExit() | ||
| } | ||
|
|
||
| run(driverUrl, executorId, hostname, cores, appId, workerUrl, userClassPath) | ||
| val createFn: (RpcEnv, SparkEnv) => CoarseGrainedExecutorBackend = { case (rpcEnv, env) => | ||
| new CoarseGrainedExecutorBackend(rpcEnv, driverUrl, executorId, hostname, cores, | ||
| userClassPath, env) | ||
| } | ||
| run(driverUrl, executorId, hostname, cores, appId, workerUrl, userClassPath, createFn) | ||
| System.exit(0) | ||
| } | ||
|
|
||
| private def printUsageAndExit() = { | ||
| // scalastyle:off println | ||
| System.err.println( | ||
| """ | ||
| |Usage: CoarseGrainedExecutorBackend [options] | ||
| | | ||
| | Options are: | ||
| | --driver-url <driverUrl> | ||
| | --executor-id <executorId> | ||
| | --hostname <hostname> | ||
| | --cores <cores> | ||
| | --app-id <appid> | ||
| | --worker-url <workerUrl> | ||
| | --user-class-path <url> | ||
| |""".stripMargin) | ||
| |Usage: CoarseGrainedExecutorBackend [options] | ||
|
Contributor
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. IntelliJ automatically corrects these indentations: I guess we could push along with the change, but please let me know if we would not want to fix this in here.
Contributor
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. Spark uses the previous indentation style in many places, so I guess that answers your question. I wouldn't exactly call this "correcting the indentation"...
Contributor
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. Yeah, I wouldn't mind reverting this. Will revert. Btw, I have a feeling that some style rule is conflicted with auto-correction (in point of IDE's view) of IDE and fixing it back is another kind of annoying. Does we have any recommend IDE configuration for avoiding this? Or does we have to deal with this manually?
Contributor
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. I don't use an IDE, can't help you there. |
||
| | | ||
| | Options are: | ||
| | --driver-url <driverUrl> | ||
| | --executor-id <executorId> | ||
| | --hostname <hostname> | ||
| | --cores <cores> | ||
| | --app-id <appid> | ||
| | --worker-url <workerUrl> | ||
| | --user-class-path <url> | ||
| |""".stripMargin) | ||
| // scalastyle:on println | ||
| System.exit(1) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.executor | ||
|
|
||
| import java.net.URL | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.{SecurityManager, SparkConf, SparkEnv} | ||
| import org.apache.spark.deploy.SparkHadoopUtil | ||
| import org.apache.spark.deploy.worker.WorkerWatcher | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.rpc.RpcEnv | ||
| import org.apache.spark.scheduler.cluster.CoarseGrainedClusterMessages.{RetrieveSparkAppConfig, SparkAppConfig} | ||
|
Contributor
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. Line too long, just use a wildcard.
Contributor
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. Looks like there're unused imports including this line. Will sort them out. |
||
| import org.apache.spark.util.{Utils, YarnContainerInfoHelper} | ||
|
|
||
| /** | ||
| * Custom implementation of CoarseGrainedExecutorBackend for YARN resource manager. | ||
| * This class extracts executor log URLs and executor attributes from system environment which | ||
| * properties are available for container being set via YARN. | ||
| */ | ||
| private[spark] class YarnCoarseGrainedExecutorBackend( | ||
|
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. Can we have some comments here as to what does this class do?
Contributor
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. Sorry missed this. Just addressed. |
||
| rpcEnv: RpcEnv, | ||
|
Contributor
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. nit: indent args and extends one more level.
Contributor
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. I'm sorry I'm not sure I understand correctly. All args are 4 spaces and
Contributor
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. Hmm, I swear I saw 2 spaces here when I looked at this code before. Ignore me. |
||
| driverUrl: String, | ||
| executorId: String, | ||
| hostname: String, | ||
| cores: Int, | ||
| userClassPath: Seq[URL], | ||
| env: SparkEnv) | ||
| extends CoarseGrainedExecutorBackend( | ||
| rpcEnv, | ||
| driverUrl, | ||
| executorId, | ||
| hostname, | ||
| cores, | ||
| userClassPath, | ||
| env) with Logging { | ||
|
|
||
| private lazy val hadoopConfiguration = SparkHadoopUtil.get.newConfiguration(env.conf) | ||
|
|
||
| override def extractLogUrls: Map[String, String] = { | ||
| YarnContainerInfoHelper.getLogUrls(hadoopConfiguration, container = None) | ||
| .getOrElse(Map()) | ||
| } | ||
|
|
||
| override def extractAttributes: Map[String, String] = { | ||
| YarnContainerInfoHelper.getAttributes(hadoopConfiguration, container = None) | ||
| .getOrElse(Map()) | ||
| } | ||
| } | ||
|
|
||
| private[spark] object YarnCoarseGrainedExecutorBackend extends Logging { | ||
|
|
||
| def main(args: Array[String]) { | ||
|
Contributor
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.
|
||
| var driverUrl: String = null | ||
|
Contributor
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. I'm not sure we also want to refactor this, as we might need to have redundant code again when one of case needs to have additional arguments. But I can also refactor if we think we can do it later when really needed.
Contributor
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. This is the same as the core argument parser and should remain the same. If and when a new argument needs to be added just for the YARN side, then you can think about refactoring this. |
||
| var executorId: String = null | ||
| var hostname: String = null | ||
| var cores: Int = 0 | ||
| var appId: String = null | ||
| var workerUrl: Option[String] = None | ||
| val userClassPath = new mutable.ListBuffer[URL]() | ||
|
|
||
| var argv = args.toList | ||
| while (!argv.isEmpty) { | ||
| argv match { | ||
| case ("--driver-url") :: value :: tail => | ||
| driverUrl = value | ||
| argv = tail | ||
| case ("--executor-id") :: value :: tail => | ||
| executorId = value | ||
| argv = tail | ||
| case ("--hostname") :: value :: tail => | ||
| hostname = value | ||
| argv = tail | ||
| case ("--cores") :: value :: tail => | ||
| cores = value.toInt | ||
| argv = tail | ||
| case ("--app-id") :: value :: tail => | ||
| appId = value | ||
| argv = tail | ||
| case ("--worker-url") :: value :: tail => | ||
| // Worker url is used in spark standalone mode to enforce fate-sharing with worker | ||
| workerUrl = Some(value) | ||
| argv = tail | ||
| case ("--user-class-path") :: value :: tail => | ||
| userClassPath += new URL(value) | ||
| argv = tail | ||
| case Nil => | ||
| case tail => | ||
| // scalastyle:off println | ||
| System.err.println(s"Unrecognized options: ${tail.mkString(" ")}") | ||
| // scalastyle:on println | ||
| printUsageAndExit() | ||
| } | ||
| } | ||
|
|
||
| if (driverUrl == null || executorId == null || hostname == null || cores <= 0 || | ||
| appId == null) { | ||
| printUsageAndExit() | ||
| } | ||
|
|
||
| val createFn: (RpcEnv, SparkEnv) => CoarseGrainedExecutorBackend = { case (rpcEnv, env) => | ||
| new YarnCoarseGrainedExecutorBackend(rpcEnv, driverUrl, executorId, hostname, cores, | ||
| userClassPath, env) | ||
| } | ||
| CoarseGrainedExecutorBackend.run(driverUrl, executorId, hostname, cores, appId, workerUrl, | ||
| userClassPath, createFn) | ||
| System.exit(0) | ||
| } | ||
|
|
||
| private def printUsageAndExit() = { | ||
| // scalastyle:off println | ||
| System.err.println( | ||
| """ | ||
| |Usage: YarnCoarseGrainedExecutorBackend [options] | ||
| | | ||
| | Options are: | ||
| | --driver-url <driverUrl> | ||
| | --executor-id <executorId> | ||
| | --hostname <hostname> | ||
| | --cores <cores> | ||
| | --app-id <appid> | ||
| | --worker-url <workerUrl> | ||
| | --user-class-path <url> | ||
| |""".stripMargin) | ||
| // scalastyle:on println | ||
| System.exit(1) | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,9 @@ private[spark] object YarnContainerInfoHelper extends Logging { | |
| val yarnConf = new YarnConfiguration(conf) | ||
| Some(Map( | ||
| "HTTP_SCHEME" -> getYarnHttpScheme(yarnConf), | ||
| "NM_HOST" -> getNodeManagerHost(container), | ||
| "NM_PORT" -> getNodeManagerPort(container), | ||
| "NM_HTTP_PORT" -> getNodeManagerHttpPort(container), | ||
| "NM_HTTP_ADDRESS" -> getNodeManagerHttpAddress(container), | ||
| "CLUSTER_ID" -> getClusterId(yarnConf).getOrElse(""), | ||
| "CONTAINER_ID" -> ConverterUtils.toString(getContainerId(container)), | ||
|
|
@@ -97,7 +100,22 @@ private[spark] object YarnContainerInfoHelper extends Logging { | |
|
|
||
| def getNodeManagerHttpAddress(container: Option[Container]): String = container match { | ||
|
Contributor
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. Same applies to all methods: now we don't have an actual usage to pass Container as parameter, but it's still safer given that it's independent on context of process. Would we want to leave this as it is, or remove this and add a note to class (or methods) javadoc? |
||
| case Some(c) => c.getNodeHttpAddress | ||
| case None => System.getenv(Environment.NM_HOST.name()) + ":" + | ||
| System.getenv(Environment.NM_HTTP_PORT.name()) | ||
| case None => getNodeManagerHost(None) + ":" + getNodeManagerHttpPort(None) | ||
| } | ||
|
|
||
| def getNodeManagerHost(container: Option[Container]): String = container match { | ||
| case Some(c) => c.getNodeHttpAddress.split(":")(0) | ||
| case None => System.getenv(Environment.NM_HOST.name()) | ||
| } | ||
|
|
||
| def getNodeManagerHttpPort(container: Option[Container]): String = container match { | ||
| case Some(c) => c.getNodeHttpAddress.split(":")(1) | ||
| case None => System.getenv(Environment.NM_HTTP_PORT.name()) | ||
| } | ||
|
|
||
| def getNodeManagerPort(container: Option[Container]): String = container match { | ||
| case Some(_) => "-1" // Just return invalid port given we cannot retrieve the value | ||
| case None => System.getenv(Environment.NM_PORT.name()) | ||
| } | ||
|
|
||
| } | ||
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.
Undo.