Skip to content
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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c65d6ea
WIP [SPARK-29779][CORE] Compact old event log files and cleanup - no …
HeartSaVioR Nov 2, 2019
bb485c7
Reflect review comments
HeartSaVioR Nov 10, 2019
87404de
Address FIXMEs
HeartSaVioR Nov 11, 2019
2944416
Add UTs for BasicEventFilter/BasicEventFilterBuilder
HeartSaVioR Nov 11, 2019
916a458
Address UTs for SQL event filter (builder)
HeartSaVioR Nov 13, 2019
0729a41
Address some more tests - leave new TODO/FIXME for tests
HeartSaVioR Nov 13, 2019
316bc17
Address review comments
HeartSaVioR Nov 13, 2019
b8a4bc1
Review comment & fix the test
HeartSaVioR Nov 13, 2019
1106bcb
Add more tests - TODO for tests addressed
HeartSaVioR Nov 14, 2019
5bd4274
Fix UT (silly mistake)
HeartSaVioR Nov 14, 2019
45e828e
Address scaladoc
HeartSaVioR Nov 14, 2019
f64388a
Address documentation
HeartSaVioR Nov 14, 2019
4559c0d
Clean up codebase a bit
HeartSaVioR Nov 14, 2019
a3b7b1f
Reflect review comments
HeartSaVioR Nov 15, 2019
a3a0c4a
More comments reflection
HeartSaVioR Nov 15, 2019
7054b2c
Fix indentation
HeartSaVioR Nov 17, 2019
5a54af9
Introduce the rate of filter to determine whether the event log for a…
HeartSaVioR Nov 25, 2019
82e268a
Clean a bit
HeartSaVioR Nov 27, 2019
e5d9250
Remove invalid comments, strengthen doc
HeartSaVioR Nov 28, 2019
b53aaf2
Address review comments
HeartSaVioR Dec 9, 2019
ef9f331
Apply PartialFunction to EventFilter
HeartSaVioR Dec 9, 2019
ed2b1e2
Refine comments
HeartSaVioR Dec 9, 2019
7db7e78
Address review comments
HeartSaVioR Dec 10, 2019
3286f9d
Reflect review comments partially
HeartSaVioR Dec 13, 2019
ab5d233
Add missed one
HeartSaVioR Dec 13, 2019
27244f3
Inline FilterRateCalculator into EventLogFileCompactor, reflect chang…
HeartSaVioR Dec 16, 2019
872ffbc
Merge branch 'master' into SPARK-29779-merge-master
HeartSaVioR Dec 17, 2019
761833b
Address incremental load on constructing EventFilterBuilder
HeartSaVioR Dec 23, 2019
e1a6e42
Reset EventFilterBuildersLoader for any exceptions
HeartSaVioR Dec 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

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?).

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job end event will be placed later than any stage/task events

I'm sure that's not true. You can see in AppStatusListener that onTaskEnd 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.

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]
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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. tasks would be much better.

case xs => xs.reduce(_ ++ _).toSet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So xs is a list of sets, right? Does stageToTasks.values.flatten.toSet work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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]
Copy link
Contributor

Choose a reason for hiding this comment

The 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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used in one place (BasicEventFilterBuilder), and there are even other calls to the BasicEventFilter constructor, so why not use the constructor call everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}

Loading