From 9e743ff6ef19d8a2c0533f92c391badcd65a4249 Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com> Date: Fri, 28 Jan 2022 17:35:38 +0300 Subject: [PATCH] chore: introspection facilities 1. Remove `get_stash` function - it doesn't show anything interesting. 2. Adjust logging levels. Also split log level initialization away from schema. --- picolib/lib.rs | 22 ++++++++-------------- picolib/traft/node.rs | 20 ++++++++++---------- picolib/traft/storage.rs | 4 ---- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/picolib/lib.rs b/picolib/lib.rs index 3b8f5a6ed1..a21c4d65e1 100644 --- a/picolib/lib.rs +++ b/picolib/lib.rs @@ -38,14 +38,6 @@ impl Stash { } } -impl std::fmt::Debug for Stash { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("") - .field("raft_node", &self.raft_node().is_some()) - .finish() - } -} - #[no_mangle] pub extern "C" fn luaopen_picolib(l: *mut std::ffi::c_void) -> c_int { if std::env::var("PICOLIB_NO_AUTORUN").is_ok() { @@ -73,10 +65,6 @@ pub extern "C" fn luaopen_picolib(l: *mut std::ffi::c_void) -> c_int { // // Export public API luamod.set("run", tlua::function0(main_run)); - luamod.set( - "get_stash", - tlua::function0(|| println!("{:?}", Stash::access())), - ); luamod.set( "raft_propose_info", tlua::function1(|x: String| raft_propose(Message::Info { msg: x })), @@ -125,6 +113,12 @@ fn main_run() { }); tarantool::set_cfg(&cfg); + tarantool::eval( + r#" + box.schema.user.grant('guest', 'super', nil, nil, {if_not_exists = true}) + box.cfg({log_level = 6}) + "#, + ); traft::Storage::init_schema(); let raft_cfg = raft::Config { @@ -155,9 +149,9 @@ fn raft_propose(msg: Message) { let stash = Stash::access(); let raft_ref = stash.raft_node(); let raft_node = raft_ref.as_ref().expect("Picodata not running yet"); - tlog!(Info, "propose {:?} ................................", msg); + tlog!(Debug, "propose {:?} ................................", msg); raft_node.propose(msg.into()); - tlog!(Info, ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); + tlog!(Debug, ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); } fn handle_committed_data(data: &[u8]) { diff --git a/picolib/traft/node.rs b/picolib/traft/node.rs index 131e3f6c4c..bfae87afda 100644 --- a/picolib/traft/node.rs +++ b/picolib/traft/node.rs @@ -77,15 +77,15 @@ fn on_ready(raft_group: &mut RawNode, handle_committed_data: fn(&[u8])) { return; } - tlog!(Info, "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"); + tlog!(Debug, "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"); // Get the `Ready` with `RawNode::ready` interface. let mut ready: raft::Ready = raft_group.ready(); - tlog!(Info, "--- {:?}", ready); + tlog!(Debug, "--- {:?}", ready); let handle_messages = |msgs: Vec<raft::Message>| { for _msg in msgs { - tlog!(Info, "--- handle message: {:?}", _msg); + tlog!(Debug, "--- handle message: {:?}", _msg); // Send messages to other peers. } }; @@ -98,14 +98,14 @@ fn on_ready(raft_group: &mut RawNode, handle_committed_data: fn(&[u8])) { if !ready.snapshot().is_empty() { // This is a snapshot, we need to apply the snapshot at first. let snap = ready.snapshot().clone(); - tlog!(Info, "--- apply_snapshot: {:?}", snap); + tlog!(Debug, "--- apply_snapshot: {:?}", snap); unimplemented!(); // store.wl().apply_snapshot(snap).unwrap(); } let handle_committed_entries = |committed_entries: Vec<raft::Entry>| { for entry in committed_entries { - tlog!(Info, "--- committed_entry: {:?}", entry); + tlog!(Debug, "--- committed_entry: {:?}", entry); Storage::persist_applied(entry.index); if entry.get_entry_type() == raft::EntryType::EntryNormal { @@ -121,7 +121,7 @@ fn on_ready(raft_group: &mut RawNode, handle_committed_data: fn(&[u8])) { // Append entries to the Raft log. let entries = ready.entries(); for entry in entries { - tlog!(Info, "--- uncommitted_entry: {:?}", entry); + tlog!(Debug, "--- uncommitted_entry: {:?}", entry); } Storage::persist_entries(entries); @@ -130,7 +130,7 @@ fn on_ready(raft_group: &mut RawNode, handle_committed_data: fn(&[u8])) { if let Some(hs) = ready.hs() { // Raft HardState changed, and we need to persist it. // let hs = hs.clone(); - tlog!(Info, "--- hard_state: {:?}", hs); + tlog!(Debug, "--- hard_state: {:?}", hs); Storage::persist_hard_state(&hs); // store.wl().set_hardstate(hs); } @@ -140,11 +140,11 @@ fn on_ready(raft_group: &mut RawNode, handle_committed_data: fn(&[u8])) { handle_messages(ready.take_persisted_messages()); } - tlog!(Info, "ADVANCE -----------------------------------------"); + tlog!(Debug, "ADVANCE -----------------------------------------"); // Advance the Raft. let mut light_rd = raft_group.advance(ready); - tlog!(Info, "--- {:?}", light_rd); + tlog!(Debug, "--- {:?}", light_rd); // Update commit index. if let Some(commit) = light_rd.commit_index() { Storage::persist_commit(commit); @@ -155,5 +155,5 @@ fn on_ready(raft_group: &mut RawNode, handle_committed_data: fn(&[u8])) { handle_committed_entries(light_rd.take_committed_entries()); // Advance the apply index. raft_group.advance_apply(); - tlog!(Info, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); + tlog!(Debug, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); } diff --git a/picolib/traft/storage.rs b/picolib/traft/storage.rs index 13039b11a2..0897772065 100644 --- a/picolib/traft/storage.rs +++ b/picolib/traft/storage.rs @@ -21,8 +21,6 @@ impl Storage { pub fn init_schema() { crate::tarantool::eval( r#" - box.schema.user.grant('guest', 'super', nil, nil, {if_not_exists = true}) - box.schema.space.create('raft_log', { if_not_exists = true, is_local = true, @@ -69,8 +67,6 @@ impl Storage { if_not_exists = true, parts = {{'raft_id'}}, }) - - box.cfg({log_level = 6}) "#, ); } -- GitLab