From e2e92bd15090affccc4fa8ad6d6f67a35e102dae Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com> Date: Wed, 29 Jun 2022 01:05:00 +0300 Subject: [PATCH] refactor: split handle_read_states function --- src/traft/node.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/traft/node.rs b/src/traft/node.rs index ee8e17c2b3..d3c8f68c3b 100644 --- a/src/traft/node.rs +++ b/src/traft/node.rs @@ -426,6 +426,26 @@ fn handle_committed_conf_change( 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( main_inbox: Mailbox<NormalRequest>, status: Rc<RefCell<Status>>, @@ -612,21 +632,6 @@ fn raft_main_loop( 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) { for msg in messages { if let Err(e) = pool.send(&msg) { -- GitLab