Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Apr 24, 2019
1 parent c24275d commit fbc0a9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
29 changes: 17 additions & 12 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,19 +1691,24 @@ impl<T: Storage> Raft<T> {
}
}
}
} else if m.get_from() == INVALID_ID || m.get_from() == self.id {
let rs = ReadState {
index: self.raft_log.committed,
request_ctx: m.take_entries()[0].take_data(),
};
self.read_states.push(rs);
} else {
let mut to_send = Message::default();
to_send.set_to(m.get_from());
to_send.set_msg_type(MessageType::MsgReadIndexResp);
to_send.set_index(self.raft_log.committed);
to_send.set_entries(m.take_entries());
self.send(to_send);
// there is only one voting member (the leader) in the cluster
if m.get_from() == INVALID_ID || m.get_from() == self.id {
// from leader itself
let rs = ReadState {
index: self.raft_log.committed,
request_ctx: m.take_entries()[0].take_data(),
};
self.read_states.push(rs);
} else {
// from learner member
let mut to_send = Message::default();
to_send.set_to(m.get_from());
to_send.set_msg_type(MessageType::MsgReadIndexResp);
to_send.set_index(self.raft_log.committed);
to_send.set_entries(m.take_entries());
self.send(to_send);
}
}
return Ok(());
}
Expand Down
28 changes: 16 additions & 12 deletions tests/integration_cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2241,20 +2241,24 @@ fn test_read_only_with_learner() {
.read_states
.drain(..)
.collect();
if read_states.is_empty() {
panic!("#{}: read_states is empty, want non-empty", i);
}
assert_eq!(
read_states.is_empty(),
false,
"#{}: read_states is empty, want non-empty",
i
);
let rs = &read_states[0];
if rs.index != wri {
panic!("#{}: read_index = {}, want {}", i, rs.index, wri)
}
assert_eq!(
rs.index, wri,
"#{}: read_index = {}, want {}",
i, rs.index, wri
);
let vec_wctx = wctx.as_bytes().to_vec();
if rs.request_ctx != vec_wctx {
panic!(
"#{}: request_ctx = {:?}, want {:?}",
i, rs.request_ctx, vec_wctx
)
}
assert_eq!(
rs.request_ctx, vec_wctx,
"#{}: request_ctx = {:?}, want {:?}",
i, rs.request_ctx, vec_wctx
);
}
}

Expand Down

0 comments on commit fbc0a9e

Please sign in to comment.