Skip to content

Commit 8e8afb3

Browse files
jerryshaosrowen
authored andcommitted
[SPARK-19545][YARN] Fix compile issue for Spark on Yarn when building against Hadoop 2.6.0~2.6.3
## What changes were proposed in this pull request? Due to the newly added API in Hadoop 2.6.4+, Spark builds against Hadoop 2.6.0~2.6.3 will meet compile error. So here still reverting back to use reflection to handle this issue. ## How was this patch tested? Manual verification. Author: jerryshao <[email protected]> Closes apache#16884 from jerryshao/SPARK-19545.
1 parent d5593f7 commit 8e8afb3

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

docs/running-on-yarn.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ To use a custom metrics.properties for the application master and executors, upd
445445
This will be used with YARN's rolling log aggregation, to enable this feature in YARN side
446446
<code>yarn.nodemanager.log-aggregation.roll-monitoring-interval-seconds</code> should be
447447
configured in yarn-site.xml.
448-
This feature can only be used with Hadoop 2.6.1+. The Spark log4j appender needs be changed to use
448+
This feature can only be used with Hadoop 2.6.4+. The Spark log4j appender needs be changed to use
449449
FileAppender or another appender that can handle the files being removed while its running. Based
450450
on the file name configured in the log4j configuration (like spark.log), the user should set the
451451
regex (spark*) to include all the log files that need to be aggregated.
@@ -524,8 +524,8 @@ pre-packaged distribution.
524524
1. In the `yarn-site.xml` on each node, add `spark_shuffle` to `yarn.nodemanager.aux-services`,
525525
then set `yarn.nodemanager.aux-services.spark_shuffle.class` to
526526
`org.apache.spark.network.yarn.YarnShuffleService`.
527-
1. Increase `NodeManager's` heap size by setting `YARN_HEAPSIZE` (1000 by default) in `etc/hadoop/yarn-env.sh`
528-
to avoid garbage collection issues during shuffle.
527+
1. Increase `NodeManager's` heap size by setting `YARN_HEAPSIZE` (1000 by default) in `etc/hadoop/yarn-env.sh`
528+
to avoid garbage collection issues during shuffle.
529529
1. Restart all `NodeManager`s in your cluster.
530530

531531
The following extra configuration options are available when the shuffle service is running on YARN:

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,27 @@ private[spark] class Client(
245245
}
246246

247247
sparkConf.get(ROLLED_LOG_INCLUDE_PATTERN).foreach { includePattern =>
248-
val logAggregationContext = Records.newRecord(classOf[LogAggregationContext])
249-
logAggregationContext.setRolledLogsIncludePattern(includePattern)
250-
sparkConf.get(ROLLED_LOG_EXCLUDE_PATTERN).foreach { excludePattern =>
251-
logAggregationContext.setRolledLogsExcludePattern(excludePattern)
248+
try {
249+
val logAggregationContext = Records.newRecord(classOf[LogAggregationContext])
250+
251+
// These two methods were added in Hadoop 2.6.4, so we still need to use reflection to
252+
// avoid compile error when building against Hadoop 2.6.0 ~ 2.6.3.
253+
val setRolledLogsIncludePatternMethod =
254+
logAggregationContext.getClass.getMethod("setRolledLogsIncludePattern", classOf[String])
255+
setRolledLogsIncludePatternMethod.invoke(logAggregationContext, includePattern)
256+
257+
sparkConf.get(ROLLED_LOG_EXCLUDE_PATTERN).foreach { excludePattern =>
258+
val setRolledLogsExcludePatternMethod =
259+
logAggregationContext.getClass.getMethod("setRolledLogsExcludePattern", classOf[String])
260+
setRolledLogsExcludePatternMethod.invoke(logAggregationContext, excludePattern)
261+
}
262+
263+
appContext.setLogAggregationContext(logAggregationContext)
264+
} catch {
265+
case NonFatal(e) =>
266+
logWarning(s"Ignoring ${ROLLED_LOG_INCLUDE_PATTERN.key} because the version of YARN " +
267+
"does not support it", e)
252268
}
253-
appContext.setLogAggregationContext(logAggregationContext)
254269
}
255270

256271
appContext

0 commit comments

Comments
 (0)