From 4fbab268366b3b884c13a473c438a4a41fe88090 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Wed, 11 Dec 2024 09:01:34 +0100 Subject: [PATCH] Obvious stuff --- src/vm/context.rs | 7 +++++++ src/vm/mod.rs | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/vm/context.rs b/src/vm/context.rs index b8c9fc6..9f9bb39 100644 --- a/src/vm/context.rs +++ b/src/vm/context.rs @@ -213,6 +213,13 @@ impl RunState { pub(crate) fn is_running(&self) -> bool { matches!(self, RunState::Running(_)) } + + pub(crate) fn name(&self) -> Option<&str> { + match self { + RunState::Running(n) => Some(n), + RunState::NotRunning => None, + } + } } pub(crate) enum EagerGetState { diff --git a/src/vm/mod.rs b/src/vm/mod.rs index e29d0da..a7d5ab1 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -34,7 +34,7 @@ use std::fmt; use std::mem::size_of; use std::time::Duration; use strum::IntoStaticStr; -use tracing::instrument; +use tracing::{enabled, instrument, Level}; mod context; pub(crate) mod errors; @@ -421,7 +421,7 @@ impl super::VM for CoreVM { ret )] fn sys_state_clear_all(&mut self) -> Result<(), Error> { - invocation_debug_logs!(self, "Executing 'Clear all state keys'"); + invocation_debug_logs!(self, "Executing 'Clear all state'"); self.context.eager_state.clear_all(); self.do_transition(SysNonCompletableEntry( "SysStateClearAll", @@ -435,12 +435,12 @@ impl super::VM for CoreVM { fields(restate.invocation.id = self.debug_invocation_id(), restate.journal.index = self.context.journal.index(), restate.protocol.version = %self.version), ret )] - fn sys_sleep(&mut self, duration: Duration) -> VMResult { - invocation_debug_logs!(self, "Executing 'Sleep for {duration:?}'"); + fn sys_sleep(&mut self, wake_up_time: Duration) -> VMResult { + invocation_debug_logs!(self, "Executing 'Sleep for {wake_up_time:?}'"); self.do_transition(SysCompletableEntry( "SysSleep", SleepEntryMessage { - wake_up_time: u64::try_from(duration.as_millis()) + wake_up_time: u64::try_from(wake_up_time.as_millis()) .expect("millis since Unix epoch should fit in u64"), ..Default::default() }, @@ -548,7 +548,7 @@ impl super::VM for CoreVM { ret )] fn sys_awakeable(&mut self) -> VMResult<(String, AsyncResultHandle)> { - invocation_debug_logs!(self, "Executing 'Awakeable'"); + invocation_debug_logs!(self, "Executing 'Create awakeable'"); self.do_transition(SysCompletableEntry( "SysAwakeable", AwakeableEntryMessage::default(), @@ -671,17 +671,29 @@ impl super::VM for CoreVM { value: RunExitResult, retry_policy: RetryPolicy, ) -> Result { - match &value { - RunExitResult::Success(_) => { - invocation_debug_logs!(self, "Storing side effect completed with success"); - } - RunExitResult::TerminalFailure(_) => { - invocation_debug_logs!(self, "Storing side effect completed with terminal failure"); + if enabled!(Level::DEBUG) { + let name = if let Ok(State::Processing { run_state, .. }) = &self.last_transition { + run_state.name() + } else { + None } - RunExitResult::RetryableFailure { .. } => { - invocation_debug_logs!(self, "Propagating side effect failure"); + .unwrap_or_default(); + match &value { + RunExitResult::Success(_) => { + invocation_debug_logs!(self, "Journaling 'run' success result named '{name}'"); + } + RunExitResult::TerminalFailure(_) => { + invocation_debug_logs!( + self, + "Journaling 'run' terminal failure result named '{name}'" + ); + } + RunExitResult::RetryableFailure { .. } => { + invocation_debug_logs!(self, "Propagating 'run' failure named '{name}'"); + } } } + self.do_transition(SysRunExit(value, retry_policy)) }