public void shutdown ( ) { if ( this . shuttingDown . getAndSet ( true ) ) { // Already being shut down LOG . warn ( "DataNode.shutdown() was called while shutting down." ) ; return ; } if ( infoServer != null ) { try { infoServer . stop ( ) ; } catch ( Exception e ) { LOG . warn ( "Exception shutting down DataNode" , e ) ; } } if ( ipcServer != null ) { ipcServer . stop ( ) ; } this . shouldRun = false ; if ( dataXceiverServer != null ) { ( ( DataXceiverServer ) this . dataXceiverServer . getRunnable ( ) ) . kill ( ) ; this . dataXceiverServer . interrupt ( ) ; // wait for all data receiver threads to exit if ( this . threadGroup != null ) { int retries = 0 ; while ( true ) { this . threadGroup . interrupt ( ) ; LOG . info ( "Waiting for threadgroup to exit, active threads is " + this . threadGroup . activeCount ( ) ) ; if ( this . threadGroup . activeCount ( ) == 0 ) { break ; } try { if ( ++ retries > 600 ) { Thread [ ] activeThreads = new Thread [ this . threadGroup . activeCount ( ) ] ; this . threadGroup . enumerate ( activeThreads , true ) ; LOG . info ( "Active Threads: " + Arrays . toString ( activeThreads ) ) ; LOG . warn ( "Waited for ThreadGroup to be empty for 10 minutes." + " SHUTTING DOWN NOW" ) ; break ; } Thread . sleep ( 1000 ) ; } catch ( InterruptedException e ) { } } } // wait for dataXceiveServer to terminate try { this . dataXceiverServer . join ( ) ; } catch ( InterruptedException ie ) { } } if ( blockCopyExecutor != null && ! blockCopyExecutor . isShutdown ( ) ) { blockCopyExecutor . shutdownNow ( ) ; } if ( namespaceManager != null ) { namespaceManager . shutDownAll ( ) ; } if ( blockScanner != null ) { blockScanner . shutdown ( ) ; } if ( directoryScanner != null ) { shutdownDirectoryScanner ( ) ; } if ( storage != null ) { try { this . storage . unlockAll ( ) ; } catch ( IOException ie ) { } } if ( data != null ) { data . shutdown ( ) ; } if ( myMetrics != null ) { setCountingLoggers ( null ) ; myMetrics . shutdown ( ) ; } this . shutdownMXBean ( ) ; }
Shut down this instance of the datanode . Returns only after shutdown is complete . This method can only be called by the offerService thread . Otherwise deadlock might occur .