baohe-zhang commented on a change in pull request #31871:
URL: https://github.com/apache/spark/pull/31871#discussion_r600618146



##########
File path: 
core/src/test/scala/org/apache/spark/executor/ExecutorMetricsPollerSuite.scala
##########
@@ -0,0 +1,46 @@
+/*
+ * 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 org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.memory.TestMemoryManager
+
+class ExecutorMetricsPollerSuite extends SparkFunSuite {
+
+  test("stage entry shouldn't be removed before a heartbeat occurs") {

Review comment:
       Added.

##########
File path: 
core/src/test/scala/org/apache/spark/executor/ExecutorMetricsPollerSuite.scala
##########
@@ -0,0 +1,46 @@
+/*
+ * 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 org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.memory.TestMemoryManager
+
+class ExecutorMetricsPollerSuite extends SparkFunSuite {
+
+  test("stage entry shouldn't be removed before a heartbeat occurs") {
+    val testMemoryManager = new TestMemoryManager(new SparkConf())
+    val poller = new ExecutorMetricsPoller(testMemoryManager, 1000, None)
+
+    poller.onTaskStart(0L, 0, 0)
+    // stage (0, 0) has an active task, so it remains on stageTCMP after 
heartbeat.
+    assert(poller.getExecutorUpdates.size === 1)
+    assert(poller.stageTCMP.size === 1)
+
+    poller.onTaskCompletion(0L, 0, 0)

Review comment:
       Done.

##########
File path: 
core/src/main/scala/org/apache/spark/executor/ExecutorMetricsPoller.scala
##########
@@ -176,6 +171,20 @@ private[spark] class ExecutorMetricsPoller(
 
     stageTCMP.replaceAll(getUpdateAndResetPeaks)
 
+    def removeIfInactive(k: StageKey, v: TCMP): TCMP = {
+      if (v.count.get == 0) {
+        logDebug(s"removing (${k._1}, ${k._2}) from stageTCMP")
+        null
+      } else {
+        v
+      }
+    }
+
+    // Remove the entry from stageTCMP if the task count reaches zero.
+    executorUpdates.foreach { case (k, v) =>

Review comment:
       Done.




-- 
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]



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

Reply via email to