private boolean gainPrimacy ( ) throws Exception { // Don't upgrade if this master's primacy is unstable. AtomicBoolean unstable = new AtomicBoolean ( false ) ; try ( Scoped scoped = mLeaderSelector . onStateChange ( state -> unstable . set ( true ) ) ) { if ( mLeaderSelector . getState ( ) != State . PRIMARY ) { unstable . set ( true ) ; } stopMasters ( ) ; LOG . info ( "Secondary stopped" ) ; mJournalSystem . gainPrimacy ( ) ; // We only check unstable here because mJournalSystem.gainPrimacy() is the only slow method if ( unstable . get ( ) ) { losePrimacy ( ) ; return false ; } } startMasters ( true ) ; mServingThread = new Thread ( ( ) -> { try { startServing ( " (gained leadership)" , " (lost leadership)" ) ; } catch ( Throwable t ) { Throwable root = ExceptionUtils . getRootCause ( t ) ; if ( ( root != null && ( root instanceof InterruptedException ) ) || Thread . interrupted ( ) ) { return ; } ProcessUtils . fatalError ( LOG , t , "Exception thrown in main serving thread" ) ; } } , "MasterServingThread" ) ; mServingThread . start ( ) ; if ( ! waitForReady ( 10 * Constants . MINUTE_MS ) ) { ThreadUtils . logAllThreads ( ) ; throw new RuntimeException ( "Alluxio master failed to come up" ) ; } LOG . info ( "Primary started" ) ; return true ; }
Upgrades the master to primary mode .