vanzin commented on a change in pull request #27085: [SPARK-29779][CORE] 
Compact old event log files and cleanup - part 1
URL: https://github.com/apache/spark/pull/27085#discussion_r362916535
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/deploy/history/BasicEventFilterBuilder.scala
 ##########
 @@ -0,0 +1,177 @@
+/*
+ * 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.deploy.history.EventFilter.FilterStatistics
+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 reject finished jobs (+ 
stages/tasks/RDDs)
+ * and dead executors.
+ */
+private[spark] class BasicEventFilterBuilder extends SparkListener with 
EventFilterBuilder {
+  private val _liveJobToStages = new mutable.HashMap[Int, Set[Int]]
+  private val _stageToTasks = new mutable.HashMap[Int, mutable.Set[Long]]
+  private val _stageToRDDs = new mutable.HashMap[Int, Set[Int]]
+  private val _liveExecutors = new mutable.HashSet[String]
+
+  private var totalJobs: Long = 0L
+  private var totalStages: Long = 0L
+  private var totalTasks: Long = 0L
+
+  def liveJobs: Set[Int] = _liveJobToStages.keySet.toSet
+  def liveStages: Set[Int] = _stageToRDDs.keySet.toSet
+  def liveTasks: Set[Long] = _stageToTasks.values.flatten.toSet
+  def liveRDDs: Set[Int] = _stageToRDDs.values.flatten.toSet
+  def liveExecutors: Set[String] = _liveExecutors.toSet
+
+  override def onJobStart(jobStart: SparkListenerJobStart): Unit = {
+    totalJobs += 1
+    jobStart.stageIds.foreach { stageId =>
+      if (_stageToRDDs.get(stageId).isEmpty) {
+        // stage submit event is not received yet
+        totalStages += 1
+        _stageToRDDs.put(stageId, Set.empty[Int])
+      }
+    }
+    _liveJobToStages += jobStart.jobId -> jobStart.stageIds.toSet
+  }
+
+  override def onJobEnd(jobEnd: SparkListenerJobEnd): Unit = {
+    val stages = _liveJobToStages.getOrElse(jobEnd.jobId, Seq.empty[Int])
+    _liveJobToStages -= jobEnd.jobId
+    // This might leave some stages and tasks if job end event comes earlier 
than stage submitted
+    // or task start event; it's not accurate but safer than dropping wrong 
events which cannot be
+    // restored.
+    _stageToTasks --= stages
+    _stageToRDDs --= stages
+  }
+
+  override def onStageSubmitted(stageSubmitted: SparkListenerStageSubmitted): 
Unit = {
+    val stageId = stageSubmitted.stageInfo.stageId
+    if (_stageToRDDs.get(stageId).isEmpty) {
+      // job start event is not received yet
+      totalStages += 1
+    }
+    _stageToRDDs.put(stageId, 
stageSubmitted.stageInfo.rddInfos.map(_.id).toSet)
+  }
+
+  override def onTaskStart(taskStart: SparkListenerTaskStart): Unit = {
+    totalTasks += 1
+    val curTasks = _stageToTasks.getOrElseUpdate(taskStart.stageId,
 
 Review comment:
   I still think this should not be `getOrElseUpdate`. Add the empty set to the 
map in `onStageSubmitted`, clean it up in `onJobEnd`, and only update it here 
if it's still in the map.
   
   Also, maybe something for the future: if a large stage is recomputed, you 
could potentially filter out a lot of data by filtering the failed attempt's 
tasks or a subset of them (e.g. only keep the failed ones).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to