private void leaderElection ( ) { loggingLog . info ( "Starting leader election for snapshot truncation daemon" ) ; try { while ( true ) { Stat stat = m_zk . exists ( VoltZK . snapshot_truncation_master , new Watcher ( ) { @ Override public void process ( WatchedEvent event ) { switch ( event . getType ( ) ) { case NodeDeleted : loggingLog . info ( "Detected the snapshot truncation leader's ephemeral node deletion" ) ; m_es . execute ( new Runnable ( ) { @ Override public void run ( ) { leaderElection ( ) ; } } ) ; break ; default : break ; } } } ) ; if ( stat == null ) { try { m_zk . create ( VoltZK . snapshot_truncation_master , null , Ids . OPEN_ACL_UNSAFE , CreateMode . EPHEMERAL ) ; m_isAutoSnapshotLeader = true ; if ( m_lastKnownSchedule != null ) { makeActivePrivate ( m_lastKnownSchedule ) ; } electedTruncationLeader ( ) ; return ; } catch ( NodeExistsException e ) { } } else { loggingLog . info ( "Leader election concluded, a leader already exists" ) ; break ; } } } catch ( Exception e ) { VoltDB . crashLocalVoltDB ( "Exception in snapshot daemon electing master via ZK" , true , e ) ; } }
Leader election for snapshots . Leader will watch for truncation and user snapshot requests