Github user squito commented on a diff in the pull request: https://github.com/apache/spark/pull/8760#discussion_r45792679 --- Diff: core/src/test/scala/org/apache/spark/scheduler/BlacklistTrackerSuite.scala --- @@ -0,0 +1,200 @@ +/* + * 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.scheduler + +import org.apache.spark.SparkFunSuite +import org.scalatest.BeforeAndAfter +import org.apache.spark.SparkConf +import org.apache.spark.TaskEndReason +import org.apache.spark.Success +import org.apache.spark.ExceptionFailure +import org.apache.spark.LocalSparkContext +import org.apache.spark.SparkContext +import org.mockito.Mockito.{when, spy} +import org.apache.spark.util.ManualClock + +class BlacklistTrackerSuite extends SparkFunSuite with BeforeAndAfter with LocalSparkContext { + + val FAILURE: TaskEndReason = new ExceptionFailure( + "Fake", + "fake failure", + Array.empty[StackTraceElement], + "fake stack trace", + None, + None) + + val stage1 = 1 + val stage2 = 2 + // Variable name can indicate basic information of taskInfo + // The format is "taskInfo_executorId_taskIndex_hostName" + val taskInfo_1_1_hostA = new TaskInfo(1L, 1, 1, 0L, "1", "hostA", TaskLocality.ANY, false) + val taskInfo_1_2_hostA = new TaskInfo(2L, 2, 1, 0L, "1", "hostA", TaskLocality.ANY, false) + val taskInfo_2_1_hostA = new TaskInfo(3L, 1, 1, 0L, "2", "hostA", TaskLocality.ANY, false) + val taskInfo_2_2_hostA = new TaskInfo(4L, 2, 1, 0L, "2", "hostA", TaskLocality.ANY, false) + val taskInfo_3_3_hostB = new TaskInfo(5L, 3, 1, 0L, "3", "hostB", TaskLocality.ANY, false) + + val clock = new ManualClock(0) + + test ("expireExecutorsInBlacklist works") { + // expire time is set to 6s + val conf = new SparkConf().setAppName("test").setMaster("local") + .set("spark.ui.enabled", "false") + .set("spark.scheduler.executorTaskBlacklistTime", "6000") + + sc = new SparkContext(conf) + val scheduler = new TaskSchedulerImpl(sc, 1) + + val tracker = new BlacklistTracker(conf, clock) + // Executor 1 into blacklist at Time 00:00:00 + tracker.updateFailureExecutors(stage1, taskInfo_1_1_hostA, FAILURE) + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set("1")) + + clock.setTime(2000) + tracker.expireExecutorsInBlackList() + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set("1")) + // Executor 1 failed again at Time 00::00:02 + tracker.updateFailureExecutors(stage1, taskInfo_1_1_hostA, FAILURE) + + clock.setTime(3000) + // Executor 2 failed at Time 00:00:03 + tracker.updateFailureExecutors(stage1, taskInfo_2_1_hostA, FAILURE) + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set("1", "2")) + + clock.setTime(6000) + tracker.expireExecutorsInBlackList() + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set("1", "2")) + + clock.setTime(8000) + tracker.expireExecutorsInBlackList() + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set("2")) + + clock.setTime(10000) + tracker.expireExecutorsInBlackList() + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set()) + } + + test("blacklist feature is off by default") { + val conf = new SparkConf().setAppName("test").setMaster("local") + .set("spark.ui.enabled", "false") + sc = new SparkContext(conf) + + val scheduler = new TaskSchedulerImpl(sc, 1) + + val tracker = new BlacklistTracker(conf, clock) + tracker.updateFailureExecutors(stage1, taskInfo_1_1_hostA, FAILURE) + tracker.updateFailureExecutors(stage1, taskInfo_2_1_hostA, FAILURE) + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set()) + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set()) + + tracker.updateFailureExecutors(stage1, taskInfo_3_3_hostB, FAILURE) + assert(tracker.executorBlacklist(scheduler, stage1, 3) === Set()) + assert(tracker.nodeBlacklist() === Set()) + } + + test("default strategy works") { + val conf = new SparkConf().setAppName("test").setMaster("local") + .set("spark.ui.enabled", "false") + .set("spark.scheduler.executorTaskBlacklistTime", "1000") + sc = new SparkContext(conf) + val scheduler = new TaskSchedulerImpl(sc, 1) + + val tracker = new BlacklistTracker(conf, clock) + tracker.updateFailureExecutors(stage1, taskInfo_1_1_hostA, FAILURE) + tracker.updateFailureExecutors(stage1, taskInfo_2_1_hostA, FAILURE) + assert(tracker.executorBlacklist(scheduler, stage1, 1) === Set("1", "2")) + assert(tracker.executorBlacklist(scheduler, stage1, 2) === Set()) + + tracker.updateFailureExecutors(stage1, taskInfo_1_1_hostA, Success) --- End diff -- can you add a really brief comment before each section (where you've put a blank line already) indicating what is going on? eg, here: "task 1 succeeds on executor 1, so we remove it from the blacklist for executor 1", and for the next one, "task 3 succeeds on executor 3, no effect on blacklist for task 1", etc.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org