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

feature: validate term value #513

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ impl<T: Storage> Raft<T> {
if raft_state.hard_state != HardState::default() {
r.load_state(&raft_state.hard_state);
}
if r.term == 0 {
GuyLewin marked this conversation as resolved.
Show resolved Hide resolved
fatal!(r.logger, "Invalid term value: 0");
}
if c.applied > 0 {
r.commit_apply(c.applied);
}
Expand Down
2 changes: 2 additions & 0 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ impl MemStorage {
// In practice, we choose the second way by assigning non-zero index to first index. Here
// we choose the first way for historical reason and easier to write tests.
core.raft_state.conf_state = ConfState::from(conf_state);
// Initialize term with a valid value (anything except 0)
core.raft_state.hard_state.term = 1;
}

/// Opens up a read lock on the storage and returns a guard handle. Use this
Expand Down