Code Monkey home page Code Monkey logo

Comments (6)

markcty avatar markcty commented on September 4, 2024

Close #73

from xline.

Phoenix500526 avatar Phoenix500526 commented on September 4, 2024

What‘s the meaning of the relevant context?

from xline.

markcty avatar markcty commented on September 4, 2024

What‘s the meaning of the relevant context?

Just miscellanea that will be used in RawCurp:

/// Relevant context for Curp
struct Context<C: Command> {
    /// Id of the server
    id: ServerId,
    /// Other server ids and addresses
    others: HashSet<ServerId>,
    /// Timeout
    timeout: Arc<ServerTimeout>,
    /// Cmd board for tracking the cmd sync results
    cb: CmdBoardRef<C>,
    /// Speculative pool
    sp: SpecPoolRef<C>,
    /// Tx to send leader changes
    leader_tx: broadcast::Sender<Option<ServerId>>,
    /// Election tick
    election_tick: AtomicU8,
    /// Heartbeat opt out flag
    hb_opt: AtomicBool,
    /// Tx to send cmds to execute and do after sync
    cmd_tx: Box<dyn CmdExeSenderInterface<C>>,
}

from xline.

Phoenix500526 avatar Phoenix500526 commented on September 4, 2024

What's the difference between LeaderState and CandidateState? How come the CandidateState is wrapped in a Mutex while the other is in a RwLock?

from xline.

markcty avatar markcty commented on September 4, 2024

What's the difference between LeaderState and CandidateState? How come the CandidateState is wrapped in a Mutex while the other is in a RwLock?

pub(super) struct State {
    /* persisted state */
    /// Current term
    pub(super) term: u64,
    /// Candidate id that received vote in current term
    pub(super) voted_for: Option<ServerId>,

    /* volatile state */
    /// Role of the server
    pub(super) role: Role,
    /// Cached id of the leader.
    pub(super) leader_id: Option<ServerId>,
}

pub(super) struct CandidateState<C> {
    /// Collected speculative pools, used for recovery
    pub(super) sps: HashMap<ServerId, Vec<Arc<C>>>,
    /// Votes received in the election
    pub(super) votes_received: u64,
}

pub(super) struct LeaderState {
    /// For each server, index of the next log entry to send to that server
    pub(super) next_index: HashMap<ServerId, usize>,
    /// For each server, index of highest log entry known to be replicated on server
    pub(super) match_index: HashMap<ServerId, usize>,
}

Why Mutex for candidate state?

  1. CandidateState is only used in election, so it's idle most of the times. While LeaderState and State is used all the times, use RwLock can increase performance.
  2. When accessing CandidateState, we always need to modify its value.

from xline.

markcty avatar markcty commented on September 4, 2024

FYI: the Log struct

pub(super) struct Log<C: Command> {
    /// Log entries
    pub(super) entries: Vec<LogEntry<C>>,
    /// Index of highest log entry known to be committed
    pub(super) commit_index: usize,
    /// Index of highest log entry applied to state machine
    pub(super) last_applied: usize,
}

from xline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.