|
17 | 17 |
|
18 | 18 | package org.apache.spark.scheduler.cluster |
19 | 19 |
|
20 | | -import java.util.concurrent.{CopyOnWriteArrayList, ScheduledExecutorService, TimeUnit} |
| 20 | +import java.util.concurrent.{CopyOnWriteArrayList, RejectedExecutionException, ScheduledExecutorService, TimeUnit} |
21 | 21 | import java.util.concurrent.atomic.{AtomicInteger, AtomicReference} |
22 | 22 | import javax.annotation.concurrent.GuardedBy |
23 | 23 |
|
@@ -413,23 +413,27 @@ class AnalyticsCoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val r |
413 | 413 | return |
414 | 414 | } |
415 | 415 |
|
416 | | - val f = Future { |
417 | | - val startTime = System.currentTimeMillis() |
418 | | - val taskDescs = scheduler.resourceOffers(offers) |
419 | | - val tasks = taskDescs.flatten |
420 | | - if (!tasks.isEmpty) { |
421 | | - launchTasks(tasks) |
422 | | - logInfo(s"makeOffers launched tasks size: ${tasks.size}," + |
423 | | - s" take ${System.currentTimeMillis() - startTime}ms") |
424 | | - } |
425 | | - }(offerExecutionContext) |
426 | | - f.onComplete { |
427 | | - case Failure(ex) => |
428 | | - // TODO handle task launch failure, either retry or abort |
429 | | - logError(s"makeOffers error with exception: ${ex.getMessage}", ex) |
430 | | - case _ => |
431 | | - }(offerExecutionContext) |
432 | | - |
| 416 | + try { |
| 417 | + val f = Future { |
| 418 | + val startTime = System.currentTimeMillis() |
| 419 | + val taskDescs = scheduler.resourceOffers(offers) |
| 420 | + val tasks = taskDescs.flatten |
| 421 | + if (!tasks.isEmpty) { |
| 422 | + launchTasks(tasks) |
| 423 | + logInfo(s"makeOffers launched tasks size: ${tasks.size}," + |
| 424 | + s" take ${System.currentTimeMillis() - startTime}ms") |
| 425 | + } |
| 426 | + }(offerExecutionContext) |
| 427 | + f.onComplete { |
| 428 | + case Failure(ex) => |
| 429 | + // TODO handle task launch failure, either retry or abort |
| 430 | + logError(s"makeOffers error with exception: ${ex.getMessage}", ex) |
| 431 | + case _ => |
| 432 | + }(offerExecutionContext) |
| 433 | + } catch { |
| 434 | + case _: RejectedExecutionException if offerExecutionContext.isShutdown => |
| 435 | + logWarning("Failed to makeOffers as executor pool was shutdown") |
| 436 | + } |
433 | 437 | } |
434 | 438 |
|
435 | 439 | private def buildWorkerOffer(executorId: String, executorData: ExecutorData) = { |
@@ -490,22 +494,27 @@ class AnalyticsCoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val r |
490 | 494 | return |
491 | 495 | } |
492 | 496 |
|
493 | | - val f = Future { |
494 | | - val startTime = System.currentTimeMillis() |
495 | | - val taskDescs = scheduler.resourceOffers(offers) |
496 | | - val tasks = taskDescs.flatten |
497 | | - if (tasks.nonEmpty) { |
498 | | - launchTasks(tasks) |
499 | | - logInfo(s"makeBatchOffers launched tasks size: ${tasks.size}," + |
500 | | - s" take ${System.currentTimeMillis() - startTime}ms") |
501 | | - } |
502 | | - }(offerExecutionContext) |
503 | | - f.onComplete { |
504 | | - case Failure(ex) => |
505 | | - // TODO handle task launch failure, either retry or abort |
506 | | - logError(s"makeBatchOffers error with exception: ${ex.getMessage}", ex) |
507 | | - case _ => |
508 | | - }(offerExecutionContext) |
| 497 | + try { |
| 498 | + val f = Future { |
| 499 | + val startTime = System.currentTimeMillis() |
| 500 | + val taskDescs = scheduler.resourceOffers(offers) |
| 501 | + val tasks = taskDescs.flatten |
| 502 | + if (tasks.nonEmpty) { |
| 503 | + launchTasks(tasks) |
| 504 | + logInfo(s"makeBatchOffers launched tasks size: ${tasks.size}," + |
| 505 | + s" take ${System.currentTimeMillis() - startTime}ms") |
| 506 | + } |
| 507 | + }(offerExecutionContext) |
| 508 | + f.onComplete { |
| 509 | + case Failure(ex) => |
| 510 | + // TODO handle task launch failure, either retry or abort |
| 511 | + logError(s"makeBatchOffers error with exception: ${ex.getMessage}", ex) |
| 512 | + case _ => |
| 513 | + }(offerExecutionContext) |
| 514 | + } catch { |
| 515 | + case _: RejectedExecutionException if offerExecutionContext.isShutdown => |
| 516 | + logWarning("Failed to makeOffers as executor pool was shutdown") |
| 517 | + } |
509 | 518 | } |
510 | 519 | } |
511 | 520 |
|
|
0 commit comments