String selectSyncHistoryOwner ( ) throws IOException { // L.1.2 Select the history of a follwer f to be the initial history // of the new epoch. Follwer f is such that for every f' in the quorum, // f'.a < f.a or (f'.a == f.a && f'.zxid <= f.zxid). long ackEpoch = persistence . getAckEpoch ( ) ; Zxid zxid = persistence . getLatestZxid ( ) ; String peerId = this . serverId ; Iterator < Map . Entry < String , PeerHandler > > iter ; iter = this . quorumMap . entrySet ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Map . Entry < String , PeerHandler > entry = iter . next ( ) ; long fEpoch = entry . getValue ( ) . getLastAckedEpoch ( ) ; Zxid fZxid = entry . getValue ( ) . getLastZxid ( ) ; if ( fEpoch > ackEpoch || ( fEpoch == ackEpoch && fZxid . compareTo ( zxid ) > 0 ) ) { ackEpoch = fEpoch ; zxid = fZxid ; peerId = entry . getKey ( ) ; } } LOG . debug ( "{} has largest acknowledged epoch {} and longest history {}" , peerId , ackEpoch , zxid ) ; if ( this . stateChangeCallback != null ) { this . stateChangeCallback . initialHistoryOwner ( peerId , ackEpoch , zxid ) ; } return peerId ; }
Finds a server who has the largest acknowledged epoch and longest history .