Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize next_idx in Raft::new #328

Open
Fullstop000 opened this issue Dec 11, 2019 · 2 comments
Open

Initialize next_idx in Raft::new #328

Fullstop000 opened this issue Dec 11, 2019 · 2 comments

Comments

@Fullstop000
Copy link
Member

Fullstop000 commented Dec 11, 2019

In Raft::new, we always create a ProgressSet with setting next_idx 1 in each Progress:

raft-rs/src/raft.rs

Lines 251 to 255 in f7f7d01

for p in voters {
let pr = Progress::new(1, r.max_inflight);
if let Err(e) = r.mut_prs().insert_voter(*p, pr) {
fatal!(r.logger, "{}", e);
}

In the situation where recovering the raft node, I think maybe we can just use the current Snapshot's meta index as same as the implementation in restore_raft :

raft-rs/src/raft.rs

Lines 1984 to 1987 in f7f7d01

let mut prs = self.prs.take().unwrap();
let next_idx = self.raft_log.last_index() + 1;
prs.restore_snapmeta(meta, next_idx, self.max_inflight);
prs.get_mut(self.id).unwrap().matched = next_idx - 1;

@hicqu
Copy link
Contributor

hicqu commented Mar 2, 2020

When a peer becomes leader, it will reset next_idx to last_index + 1 for all followers. So I think it's OK?

@Fullstop000
Copy link
Member Author

Fullstop000 commented Mar 3, 2020

I just want to make the implementation stay consistent with resotre_snapmeta :). Feel free to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants