Skip to content
Snippets Groups Projects
Commit e2e92bd1 authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

refactor: split handle_read_states function

parent 7f3812da
No related branches found
No related tags found
1 merge request!157refactor: cut raft_main loop into pieces
...@@ -426,6 +426,26 @@ fn handle_committed_conf_change( ...@@ -426,6 +426,26 @@ fn handle_committed_conf_change(
Storage::persist_conf_state(&conf_state).unwrap(); Storage::persist_conf_state(&conf_state).unwrap();
} }
fn handle_read_states(
read_states: Vec<raft::ReadState>,
notifications: &mut HashMap<LogicalClock, Notify>,
) {
for rs in read_states {
let ctx = match traft::EntryContextNormal::read_from_bytes(&rs.request_ctx) {
Ok(Some(v)) => v,
Ok(None) => continue,
Err(_) => {
tlog!(Error, "abnormal entry, read_state = {rs:?}");
continue;
}
};
if let Some(notify) = notifications.remove(&ctx.lc) {
notify.notify_ok(rs.index);
}
}
}
fn raft_main_loop( fn raft_main_loop(
main_inbox: Mailbox<NormalRequest>, main_inbox: Mailbox<NormalRequest>,
status: Rc<RefCell<Status>>, status: Rc<RefCell<Status>>,
...@@ -612,21 +632,6 @@ fn raft_main_loop( ...@@ -612,21 +632,6 @@ fn raft_main_loop(
let mut ready: raft::Ready = raw_node.ready(); let mut ready: raft::Ready = raw_node.ready();
fn handle_read_states(
read_states: Vec<raft::ReadState>,
notifications: &mut HashMap<LogicalClock, Notify>,
) {
for rs in read_states {
if let Some(ctx) = traft::EntryContextNormal::read_from_bytes(&rs.request_ctx)
.expect("Abnormal entry in message context")
{
if let Some(notify) = notifications.remove(&ctx.lc) {
notify.notify_ok(rs.index);
}
}
}
}
fn handle_messages(messages: Vec<raft::Message>, pool: &ConnectionPool) { fn handle_messages(messages: Vec<raft::Message>, pool: &ConnectionPool) {
for msg in messages { for msg in messages {
if let Err(e) = pool.send(&msg) { if let Err(e) = pool.send(&msg) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment