-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-29779][CORE] Compact old event log files and cleanup #26416
Changes from 15 commits
c65d6ea
bb485c7
87404de
2944416
916a458
0729a41
316bc17
b8a4bc1
1106bcb
5bd4274
45e828e
f64388a
4559c0d
a3b7b1f
a3a0c4a
7054b2c
5a54af9
82e268a
e5d9250
b53aaf2
ef9f331
ed2b1e2
7db7e78
3286f9d
ab5d233
27244f3
872ffbc
761833b
e1a6e42
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
org.apache.spark.deploy.history.BasicEventFilterBuilder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
* 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.deploy.history | ||
|
||
import scala.collection.mutable | ||
|
||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.scheduler._ | ||
|
||
/** | ||
* This class tracks both live jobs and live executors, and pass the list to the | ||
* [[BasicEventFilter]] to help BasicEventFilter to filter out finished jobs | ||
* (+ stages/tasks/RDDs) and dead executors. | ||
*/ | ||
private[spark] class BasicEventFilterBuilder extends SparkListener with EventFilterBuilder { | ||
private val _liveJobToStages = new mutable.HashMap[Int, Seq[Int]] | ||
private val _stageToTasks = new mutable.HashMap[Int, mutable.Set[Long]] | ||
private val _stageToRDDs = new mutable.HashMap[Int, Seq[Int]] | ||
private val _liveExecutors = new mutable.HashSet[String] | ||
|
||
def liveJobToStages: Map[Int, Seq[Int]] = _liveJobToStages.toMap | ||
def stageToTasks: Map[Int, Set[Long]] = _stageToTasks.mapValues(_.toSet).toMap | ||
def stageToRDDs: Map[Int, Seq[Int]] = _stageToRDDs.toMap | ||
def liveExecutors: Set[String] = _liveExecutors.toSet | ||
|
||
override def onJobStart(jobStart: SparkListenerJobStart): Unit = { | ||
_liveJobToStages += jobStart.jobId -> jobStart.stageIds | ||
} | ||
|
||
override def onJobEnd(jobEnd: SparkListenerJobEnd): Unit = { | ||
val stages = _liveJobToStages.getOrElse(jobEnd.jobId, Seq.empty[Int]) | ||
_liveJobToStages -= jobEnd.jobId | ||
_stageToTasks --= stages | ||
_stageToRDDs --= stages | ||
} | ||
|
||
override def onStageSubmitted(stageSubmitted: SparkListenerStageSubmitted): Unit = { | ||
_stageToRDDs.getOrElseUpdate(stageSubmitted.stageInfo.stageId, | ||
stageSubmitted.stageInfo.rddInfos.map(_.id)) | ||
} | ||
|
||
override def onTaskStart(taskStart: SparkListenerTaskStart): Unit = { | ||
val curTasks = _stageToTasks.getOrElseUpdate(taskStart.stageId, | ||
mutable.HashSet[Long]()) | ||
curTasks += taskStart.taskInfo.taskId | ||
} | ||
|
||
override def onExecutorAdded(executorAdded: SparkListenerExecutorAdded): Unit = { | ||
_liveExecutors += executorAdded.executorId | ||
} | ||
|
||
override def onExecutorRemoved(executorRemoved: SparkListenerExecutorRemoved): Unit = { | ||
_liveExecutors -= executorRemoved.executorId | ||
} | ||
|
||
override def createFilter(): EventFilter = BasicEventFilter(this) | ||
} | ||
|
||
/** | ||
* This class provides the functionality to filter out events which are related to the finished | ||
* jobs based on the given information. This class only deals with job related events, and returns | ||
* either Some(true) or Some(false) - successors should override the methods if they don't want to | ||
* return Some(false) for finished jobs and related events. | ||
*/ | ||
private[spark] abstract class JobEventFilter( | ||
jobToStages: Map[Int, Seq[Int]], | ||
stageToTasks: Map[Int, Set[Long]], | ||
stageToRDDs: Map[Int, Seq[Int]]) extends EventFilter with Logging { | ||
|
||
private val liveTasks: Set[Long] = stageToTasks.values match { | ||
case xs if xs.isEmpty => Set.empty[Long] | ||
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. Every time I get to this line I start asking "what is xs". Maybe use a less cryptic name? 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 sorry about the confusion. I might still have a strong feeling of Scala examples for beginner, sigh. |
||
case xs => xs.reduce(_ ++ _).toSet | ||
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. So 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 feel I tried to deal with something similar before and it didn't work, but I might be missing. Let me try it again. 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 working. I might be puzzled at that time. Thanks for the providing nice one-liner shortcut! |
||
} | ||
|
||
private val liveRDDs: Set[Int] = stageToRDDs.values match { | ||
case xs if xs.isEmpty => Set.empty[Int] | ||
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 comments. |
||
case xs => xs.reduce(_ ++ _).toSet | ||
} | ||
|
||
logDebug(s"jobs : ${jobToStages.keySet}") | ||
logDebug(s"stages in jobs : ${jobToStages.values.flatten}") | ||
logDebug(s"stages : ${stageToTasks.keySet}") | ||
logDebug(s"tasks in stages : ${stageToTasks.values.flatten}") | ||
logDebug(s"RDDs in stages : ${stageToRDDs.values.flatten}") | ||
|
||
override def filterStageCompleted(event: SparkListenerStageCompleted): Option[Boolean] = { | ||
Some(stageToTasks.contains(event.stageInfo.stageId)) | ||
} | ||
|
||
override def filterStageSubmitted(event: SparkListenerStageSubmitted): Option[Boolean] = { | ||
Some(stageToTasks.contains(event.stageInfo.stageId)) | ||
} | ||
|
||
override def filterTaskStart(event: SparkListenerTaskStart): Option[Boolean] = { | ||
Some(liveTasks.contains(event.taskInfo.taskId)) | ||
} | ||
|
||
override def filterTaskGettingResult(event: SparkListenerTaskGettingResult): Option[Boolean] = { | ||
Some(liveTasks.contains(event.taskInfo.taskId)) | ||
} | ||
|
||
override def filterTaskEnd(event: SparkListenerTaskEnd): Option[Boolean] = { | ||
Some(liveTasks.contains(event.taskInfo.taskId)) | ||
} | ||
|
||
override def filterJobStart(event: SparkListenerJobStart): Option[Boolean] = { | ||
Some(jobToStages.contains(event.jobId)) | ||
} | ||
|
||
override def filterJobEnd(event: SparkListenerJobEnd): Option[Boolean] = { | ||
Some(jobToStages.contains(event.jobId)) | ||
} | ||
|
||
override def filterUnpersistRDD(event: SparkListenerUnpersistRDD): Option[Boolean] = { | ||
Some(liveRDDs.contains(event.rddId)) | ||
} | ||
|
||
override def filterExecutorMetricsUpdate( | ||
event: SparkListenerExecutorMetricsUpdate): Option[Boolean] = { | ||
Some(event.accumUpdates.exists { case (_, stageId, _, _) => | ||
stageToTasks.contains(stageId) | ||
}) | ||
} | ||
|
||
override def filterSpeculativeTaskSubmitted( | ||
event: SparkListenerSpeculativeTaskSubmitted): Option[Boolean] = { | ||
Some(stageToTasks.contains(event.stageId)) | ||
} | ||
} | ||
|
||
/** | ||
* This class filters out events which are related to the finished jobs or dead executors, | ||
* based on the given information. The events which are not related to the job and executor | ||
* will be considered as "Don't mind". | ||
*/ | ||
private[spark] class BasicEventFilter( | ||
_liveJobToStages: Map[Int, Seq[Int]], | ||
_stageToTasks: Map[Int, Set[Long]], | ||
_stageToRDDs: Map[Int, Seq[Int]], | ||
liveExecutors: Set[String]) | ||
extends JobEventFilter(_liveJobToStages, _stageToTasks, _stageToRDDs) with Logging { | ||
|
||
logDebug(s"live executors : $liveExecutors") | ||
|
||
override def filterExecutorAdded(event: SparkListenerExecutorAdded): Option[Boolean] = { | ||
Some(liveExecutors.contains(event.executorId)) | ||
} | ||
|
||
override def filterExecutorRemoved(event: SparkListenerExecutorRemoved): Option[Boolean] = { | ||
Some(liveExecutors.contains(event.executorId)) | ||
} | ||
|
||
override def filterExecutorBlacklisted( | ||
event: SparkListenerExecutorBlacklisted): Option[Boolean] = { | ||
Some(liveExecutors.contains(event.executorId)) | ||
} | ||
|
||
override def filterExecutorUnblacklisted( | ||
event: SparkListenerExecutorUnblacklisted): Option[Boolean] = { | ||
Some(liveExecutors.contains(event.executorId)) | ||
} | ||
|
||
override def filterStageExecutorMetrics( | ||
event: SparkListenerStageExecutorMetrics): Option[Boolean] = { | ||
Some(liveExecutors.contains(event.execId)) | ||
} | ||
} | ||
|
||
private[spark] object BasicEventFilter { | ||
def apply(builder: BasicEventFilterBuilder): BasicEventFilter = { | ||
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 only used in one place ( 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 was trying to encapsulate these lists and only provide them in here, but changed my mind (don't remember why). We can do it in constructor. Thanks! |
||
new BasicEventFilter( | ||
builder.liveJobToStages, | ||
builder.stageToTasks, | ||
builder.stageToRDDs, | ||
builder.liveExecutors) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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.deploy.history | ||
|
||
import org.apache.spark.scheduler._ | ||
|
||
/** | ||
* EventFilterBuilder provides the interface to gather the information from events being received | ||
* by [[SparkListenerInterface]], and create a new [[EventFilter]] instance which leverages | ||
* information gathered to decide whether the event should be filtered or not. | ||
*/ | ||
private[spark] trait EventFilterBuilder extends SparkListenerInterface { | ||
def createFilter(): EventFilter | ||
} | ||
|
||
/** | ||
* [[EventFilter]] decides whether the given event should be filtered in, or filtered out when | ||
* compacting event log files. | ||
* | ||
* The meaning of return values of each filterXXX method are following: | ||
* - Some(true): Filter in this event. | ||
* - Some(false): Filter out this event. | ||
* - None: Don't mind about this event. No problem even other filters decide to filter out. | ||
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. Would be good to mention what happens when all the filters vote with 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 guess FilteredEventLogFileRewriter scaladoc covers it, but please let me know if it doesn't seem to be sufficient. 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. Reading it together makes it clear + there is a reference so I'm fine with it. |
||
* | ||
* Please refer [[FilteredEventLogFileRewriter]] for more details on how the filter will be used. | ||
*/ | ||
private[spark] trait EventFilter { | ||
vanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def filterStageCompleted(event: SparkListenerStageCompleted): Option[Boolean] = None | ||
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. So the result can have three kind of values: Some(true), Some(false), None. Some(true) means "yes the event should be retained", and Some(false) means "no the event can be dropped", and None means "I'm not aware of this event, I don't care.". The event will be filtered "out" only when all filters except ones returning None return Some(false). |
||
|
||
def filterStageSubmitted(event: SparkListenerStageSubmitted): Option[Boolean] = None | ||
|
||
def filterTaskStart(event: SparkListenerTaskStart): Option[Boolean] = None | ||
|
||
def filterTaskGettingResult(event: SparkListenerTaskGettingResult): Option[Boolean] = None | ||
|
||
def filterTaskEnd(event: SparkListenerTaskEnd): Option[Boolean] = None | ||
|
||
def filterJobStart(event: SparkListenerJobStart): Option[Boolean] = None | ||
|
||
def filterJobEnd(event: SparkListenerJobEnd): Option[Boolean] = None | ||
|
||
def filterEnvironmentUpdate(event: SparkListenerEnvironmentUpdate): Option[Boolean] = None | ||
|
||
def filterBlockManagerAdded(event: SparkListenerBlockManagerAdded): Option[Boolean] = None | ||
|
||
def filterBlockManagerRemoved(event: SparkListenerBlockManagerRemoved): Option[Boolean] = None | ||
|
||
def filterUnpersistRDD(event: SparkListenerUnpersistRDD): Option[Boolean] = None | ||
|
||
def filterApplicationStart(event: SparkListenerApplicationStart): Option[Boolean] = None | ||
|
||
def filterApplicationEnd(event: SparkListenerApplicationEnd): Option[Boolean] = None | ||
|
||
def filterExecutorMetricsUpdate(event: SparkListenerExecutorMetricsUpdate): Option[Boolean] = None | ||
|
||
def filterStageExecutorMetrics(event: SparkListenerStageExecutorMetrics): Option[Boolean] = None | ||
|
||
def filterExecutorAdded(event: SparkListenerExecutorAdded): Option[Boolean] = None | ||
|
||
def filterExecutorRemoved(event: SparkListenerExecutorRemoved): Option[Boolean] = None | ||
|
||
def filterExecutorBlacklisted(event: SparkListenerExecutorBlacklisted): Option[Boolean] = None | ||
|
||
def filterExecutorBlacklistedForStage( | ||
event: SparkListenerExecutorBlacklistedForStage): Option[Boolean] = None | ||
|
||
def filterNodeBlacklistedForStage( | ||
event: SparkListenerNodeBlacklistedForStage): Option[Boolean] = None | ||
|
||
def filterExecutorUnblacklisted(event: SparkListenerExecutorUnblacklisted): Option[Boolean] = None | ||
|
||
def filterNodeBlacklisted(event: SparkListenerNodeBlacklisted): Option[Boolean] = None | ||
|
||
def filterNodeUnblacklisted(event: SparkListenerNodeUnblacklisted): Option[Boolean] = None | ||
|
||
def filterBlockUpdated(event: SparkListenerBlockUpdated): Option[Boolean] = None | ||
|
||
def filterSpeculativeTaskSubmitted( | ||
event: SparkListenerSpeculativeTaskSubmitted): Option[Boolean] = None | ||
|
||
def filterOtherEvent(event: SparkListenerEvent): Option[Boolean] = None | ||
} | ||
|
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.
I know that task end events can arrive after a stage end; but just in case the start event also can, maybe it's safer to check if the stage is really active (by checking
_liveJobToStages
?).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.
Honestly I'm not sure how much the events can be out of order. The code assumes job start event will be placed earlier than any stage/task events in the job, and job end event will be placed later than any stage/task events in the job. If that's not true, may need to revisit the whole builder logic.
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.
I'm sure that's not true. You can see in
AppStatusListener
thatonTaskEnd
has logic to clean up stuff if the event arrives after a job / stage end.I'm actually going further here, and saying you should double check that the stage is active when a start event arrives, or maybe change the way you're tracking things here if being exact is important.