/// Creates a Sequence Paxos replica.
Creates a Sequence Paxos replica.
Creates a Sequence Paxos replica .
pub fn with(config: SequencePaxosConfig, storage: B) -> Self {
        let pid = config.pid;
        let peers = config.peers;
        let config_id = config.configuration_id;
        let num_nodes = &peers.len() + 1;
        let majority = num_nodes / 2 + 1;
        let max_peer_pid = peers.iter().max().unwrap();
        let max_pid = *std::cmp::max(max_peer_pid, &pid) as usize;
        let (state, leader, n_leader, lds) = match config.skip_prepare_use_leader {
            Some(l) => {
                let (role, lds) = if l.pid == pid {
                    // we are leader in new config
                    let mut v = vec![None; max_pid];
                    for idx in peers.iter().map(|pid| *pid as usize - 1) {
                        // this works as a promise
                        v[idx] = Some(0);
                    }
                    (Role::Leader, Some(v))
                } else {
                    (Role::Follower, None)
                };
                let state = (role, Phase::FirstAccept);
                (state, l.pid, l, lds)
            }
            None => {
                let state = (Role::Follower, Phase::None);
                let lds = None;
                (state, 0, Ballot::default(), lds)
            }
        };
        let path = config.logger_file_path;
        let l = config.logger.unwrap_or_else(|| {
            let s = path.unwrap_or_else(|| format!("logs/paxos_{}.log", pid));
            create_logger(s.as_str())
        });
        info!(l, "Paxos component pid: {} created!", pid);
        let mut paxos = SequencePaxos {
            storage,
            pid,
            config_id,
            peers,
            state,
            pending_proposals: vec![],
            pending_stopsign: None,
            leader,
            outgoing: Vec::with_capacity(BUFFER_SIZE),
            logger: l,
            leader_state: LeaderState::with(n_leader, lds, max_pid, majority),
            latest_accepted_meta: None,
            buffer_size: config.buffer_size,
            s: PhantomData,
        };
        paxos.storage.set_promise(n_leader);
        paxos
    }
pub fn with ( config : SequencePaxosConfig , storage : B ) -> Self { let pid = config . pid ; let peers = config . peers ; let config_id = config . configuration_id ; let num_nodes = & peers . len ( ) + 1 ; let majority = num_nodes / 2 + 1 ; let max_peer_pid = peers . iter ( ) . max ( ) . unwrap ( ) ; let max_pid = * std :: cmp :: max ( max_peer_pid , & pid ) as usize ; let ( state , leader , n_leader , lds ) = match config . skip_prepare_use_leader { Some ( l ) => { let ( role , lds ) = if l . pid == pid { // we are leader in new config let mut v = vec ! [ None max_pid ] ; for idx in peers . iter ( ) . map ( | pid | * pid as usize - 1 ) { // this works as a promise v [ idx ] = Some ( 0 ) ; } ( Role :: Leader , Some ( v ) ) } else { ( Role :: Follower , None ) } ; let state = ( role , Phase :: FirstAccept ) ; ( state , l . pid , l , lds ) } None => { let state = ( Role :: Follower , Phase :: None ) ; let lds = None ; ( state , 0 , Ballot :: default ( ) , lds ) } } ; let path = config . logger_file_path ; let l = config . logger . unwrap_or_else ( | | { let s = path . unwrap_or_else ( | | format ! ( " " pid ) ) ; create_logger ( s . as_str ( ) ) } ) ; info ! ( l " " pid ) ; let mut paxos = SequencePaxos { storage , pid , config_id , peers , state , pending_proposals : vec ! [ ] , pending_stopsign : None , leader , outgoing : Vec :: with_capacity ( BUFFER_SIZE ) , logger : l , leader_state : LeaderState :: with ( n_leader , lds , max_pid , majority ) , latest_accepted_meta : None , buffer_size : config . buffer_size , s : PhantomData , } ; paxos . storage . set_promise ( n_leader ) ; paxos }
Creates a Sequence Paxos replica.
Creates a Sequence Paxos replica .
config
SequencePaxosConfig
storage
B