@@ -285,39 +285,43 @@ private[spark] class CoarseGrainedExecutorBackend(
285285 // is viewed as acceptable to minimize introduction of any new locking structures in critical
286286 // code paths.
287287
288- val shutdownThread = new Thread () {
289- var lastTaskRunningTime = System .nanoTime()
290- val sleep_time = 1000 // 1s
291-
292- while (true ) {
293- logInfo(" Checking to see if we can shutdown." )
294- if (executor == null || executor.numRunningTasks == 0 ) {
295- if (env.conf.get(STORAGE_DECOMMISSION_ENABLED )) {
296- logInfo(" No running tasks, checking migrations" )
297- val allBlocksMigrated = env.blockManager.lastMigrationInfo()
298- // We can only trust allBlocksMigrated boolean value if there were no tasks running
299- // since the start of computing it.
300- if (allBlocksMigrated._2 &&
301- (allBlocksMigrated._1 > lastTaskRunningTime)) {
302- logInfo(" No running tasks, all blocks migrated, stopping." )
303- exitExecutor(0 , " Finished decommissioning" , notifyDriver = true )
288+ val shutdownExec = ThreadUtils .newDaemonSingleThreadExecutor(" wait for decommissioning" )
289+ val shutdownRunnable = new Runnable () {
290+ override def run (): Unit = {
291+ var lastTaskRunningTime = System .nanoTime()
292+ val sleep_time = 1000 // 1s
293+
294+ while (true ) {
295+ logInfo(" Checking to see if we can shutdown." )
296+ if (executor == null || executor.numRunningTasks == 0 ) {
297+ if (env.conf.get(STORAGE_DECOMMISSION_ENABLED )) {
298+ logInfo(" No running tasks, checking migrations" )
299+ val allBlocksMigrated = env.blockManager.lastMigrationInfo()
300+ // We can only trust allBlocksMigrated boolean value if there were no tasks running
301+ // since the start of computing it.
302+ if (allBlocksMigrated._2 &&
303+ (allBlocksMigrated._1 > lastTaskRunningTime)) {
304+ logInfo(" No running tasks, all blocks migrated, stopping." )
305+ exitExecutor(0 , " Finished decommissioning" , notifyDriver = true )
306+ } else {
307+ logInfo(" All blocks not yet migrated." )
308+ }
304309 } else {
305- logInfo(" All blocks not yet migrated." )
310+ logInfo(" No running tasks, no block migration configured, stopping." )
311+ exitExecutor(0 , " Finished decommissioning" , notifyDriver = true )
306312 }
313+ Thread .sleep(sleep_time)
307314 } else {
308- logInfo(" No running tasks, no block migration configured, stopping." )
309- exitExecutor(0 , " Finished decommissioning" , notifyDriver = true )
315+ logInfo(" Blocked from shutdown by running task" )
316+ // If there is a running task it could store blocks, so make sure we wait for a
317+ // migration loop to complete after the last task is done.
318+ Thread .sleep(sleep_time)
319+ lastTaskRunningTime = System .nanoTime()
310320 }
311- Thread .sleep(sleep_time)
312- } else {
313- logInfo(" Blocked from shutdown by running task" )
314- // If there is a running task it could store blocks, so make sure we wait for a
315- // migration loop to complete after the last task is done.
316- Thread .sleep(sleep_time)
317- lastTaskRunningTime = System .nanoTime()
318321 }
319322 }
320323 }
324+ shutdownExec.submit(shutdownRunnable)
321325 logInfo(" Will exit when finished decommissioning" )
322326 // Return true since we are handling a signal
323327 true
0 commit comments