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

*: allow index start from 0 #353

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion benches/suites/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn test_ready_raft_node(logger: &slog::Logger) -> RawNode<MemStorage> {
let mut e = Entry::default();
e.data = vec![0; 32 * 1024];
e.context = vec![];
e.index = i + 1;
e.index = i;
e.term = 1;
entries.push(e);
}
Expand Down
12 changes: 9 additions & 3 deletions examples/five_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::time::{Duration, Instant};
use std::{str, thread};

use protobuf::Message as PbMessage;
use raft::eraftpb::ConfState;
use raft::storage::MemStorage;
use raft::{prelude::*, StateRole};
use regex::Regex;
Expand Down Expand Up @@ -175,8 +174,15 @@ impl Node {
let mut cfg = example_config();
cfg.id = id;
let logger = logger.new(o!("tag" => format!("peer_{}", id)));

let storage = MemStorage::new_with_conf_state(ConfState::from((vec![id], vec![])));
let mut s = Snapshot::default();
// Because we don't use the same configuration to initialize every node, so we use
// a non-zero index to force new followers catch up logs by snapshot first, which will
// bring all nodes to the same initial state.
s.mut_metadata().index = 1;
s.mut_metadata().term = 1;
s.mut_metadata().mut_conf_state().voters = vec![1];
let storage = MemStorage::new();
storage.wl().apply_snapshot(s).unwrap();
let raft_group = Some(RawNode::new(&cfg, storage, &logger).unwrap());
Node {
raft_group,
Expand Down
2 changes: 1 addition & 1 deletion harness/tests/failpoints_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_reject_stale_term_message() {
let l = default_logger();
let mut r = new_test_raft(1, vec![1, 2, 3], 10, 1, new_storage(), &l);
fail::cfg("before_step", "panic").unwrap();
r.load_state(&hard_state(2, 1, 0));
r.load_state(&hard_state(2, 0, 0));

let mut m = new_message(0, 0, MessageType::MsgAppend, 0);
m.term = r.term - 1;
Expand Down
Loading