From 6cc4313d058a2fe16ab9a705bcf61fdfa06dd687 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 30 Oct 2024 14:50:51 +0100 Subject: [PATCH] fix rebase fallout + use Arc more for reducers --- crates/core/src/db/relational_db.rs | 4 ++-- crates/core/src/execution_context.rs | 6 +++--- crates/core/src/host/module_host.rs | 9 ++++----- crates/core/src/host/wasm_common/module_host_actor.rs | 8 ++++---- crates/core/src/host/wasmtime/wasm_instance_env.rs | 9 +++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/core/src/db/relational_db.rs b/crates/core/src/db/relational_db.rs index f4b3031e431..784ecb28110 100644 --- a/crates/core/src/db/relational_db.rs +++ b/crates/core/src/db/relational_db.rs @@ -2424,9 +2424,9 @@ mod tests { arg_bsatn, } = ReducerContext::try_from(&input).unwrap(); if i == 0 { - assert_eq!(reducer_name, "__identity_connected__"); + assert_eq!(&*reducer_name, "__identity_connected__"); } else { - assert_eq!(reducer_name, "abstract_concrete_proxy_factory_impl"); + assert_eq!(&*reducer_name, "abstract_concrete_proxy_factory_impl"); } assert!( arg_bsatn.is_empty(), diff --git a/crates/core/src/execution_context.rs b/crates/core/src/execution_context.rs index ee80464c241..d44115f5f41 100644 --- a/crates/core/src/execution_context.rs +++ b/crates/core/src/execution_context.rs @@ -117,7 +117,7 @@ pub struct ExecutionContext { #[derive(Clone)] pub struct ReducerContext { /// The name of the reducer. - pub name: String, + pub name: Arc, /// The [`Identity`] of the caller. pub caller_identity: Identity, /// The [`Address`] of the caller. @@ -172,7 +172,7 @@ impl TryFrom<&txdata::Inputs> for ReducerContext { let timestamp = bsatn::from_reader(args)?; Ok(Self { - name: inputs.reducer_name.to_string(), + name: inputs.reducer_name.as_str().into(), caller_identity, caller_address, timestamp, @@ -278,7 +278,7 @@ impl ExecutionContext { /// If this is a reducer context, returns the name of the reducer. #[inline] pub fn reducer_name(&self) -> &str { - self.reducer.as_ref().map(|ctx| ctx.name.as_str()).unwrap_or_default() + self.reducer.as_ref().map(|ctx| &*ctx.name).unwrap_or_default() } /// If this is a reducer context, returns the full reducer metadata. diff --git a/crates/core/src/host/module_host.rs b/crates/core/src/host/module_host.rs index 720c254fa0f..bec86e04a59 100644 --- a/crates/core/src/host/module_host.rs +++ b/crates/core/src/host/module_host.rs @@ -592,7 +592,8 @@ impl ModuleHost { let db = self.db(); let workload = || { Workload::Reducer(ReducerContext { - name: reducer_name.to_owned(), + // TODO(perf, centril): consider allowing `&'static str | Arc`, perhaps flexstr. + name: reducer_name.into(), caller_identity, caller_address, timestamp: Timestamp::now(), @@ -794,7 +795,7 @@ impl ModuleHost { tx.ctx = ExecutionContext::with_workload( tx.ctx.database_identity(), Workload::Reducer(ReducerContext { - name: reducer.into(), + name: reducer, caller_identity: params.caller_identity, caller_address: params.caller_address, timestamp: Timestamp::now(), @@ -932,9 +933,7 @@ impl ModuleHost { let db = self.db(); let auth = self.auth_ctx_for(identity); let (table_names, table_ids): (Vec<_>, Vec<_>) = db - .with_read_only(&ExecutionContext::internal(db.database_identity()), |tx| { - db.get_all_tables(tx) - }) + .with_read_only(Workload::Internal, |tx| db.get_all_tables(tx)) .expect("ids_to_name: database in a broken state?") .iter() .filter(|schema| is_table_visible(schema, &auth)) diff --git a/crates/core/src/host/wasm_common/module_host_actor.rs b/crates/core/src/host/wasm_common/module_host_actor.rs index e90116e4532..975ce0424ba 100644 --- a/crates/core/src/host/wasm_common/module_host_actor.rs +++ b/crates/core/src/host/wasm_common/module_host_actor.rs @@ -429,7 +429,7 @@ impl WasmModuleInstance { let op = ReducerOp { id: reducer_id, - name: reducer_name, + name: reducer_name_arc.clone(), caller_identity: &caller_identity, caller_address: &caller_address, timestamp, @@ -444,7 +444,7 @@ impl WasmModuleInstance { }); let _guard = WORKER_METRICS .reducer_plus_query_duration - .with_label_values(&address, op.name) + .with_label_values(&address, reducer_name) .with_timer(tx.timer); let mut tx_slot = self.instance.instance_env().tx.clone(); @@ -576,7 +576,7 @@ impl WasmModuleInstance { #[derive(Clone, Debug)] pub struct ReducerOp<'a> { pub id: ReducerId, - pub name: &'a str, + pub name: Arc, pub caller_identity: &'a Identity, pub caller_address: &'a Address, pub timestamp: Timestamp, @@ -596,7 +596,7 @@ impl From> for execution_context::ReducerContext { }: ReducerOp<'_>, ) -> Self { Self { - name: name.to_owned(), + name, caller_identity: *caller_identity, caller_address: *caller_address, timestamp, diff --git a/crates/core/src/host/wasmtime/wasm_instance_env.rs b/crates/core/src/host/wasmtime/wasm_instance_env.rs index faf640b6d73..a7de34b57d9 100644 --- a/crates/core/src/host/wasmtime/wasm_instance_env.rs +++ b/crates/core/src/host/wasmtime/wasm_instance_env.rs @@ -1,5 +1,6 @@ #![allow(clippy::too_many_arguments)] +use std::sync::Arc; use std::time::Instant; use crate::database_logger::{BacktraceFrame, BacktraceProvider, ModuleBacktrace, Record}; @@ -72,7 +73,7 @@ pub(super) struct WasmInstanceEnv { call_times: CallTimes, /// The last, including current, reducer to be executed by this environment. - reducer_name: String, + reducer_name: Arc, } const CALL_REDUCER_ARGS_SOURCE: u32 = 1; @@ -96,7 +97,7 @@ impl WasmInstanceEnv { timing_spans: Default::default(), reducer_start, call_times: CallTimes::new(), - reducer_name: String::from(""), + reducer_name: "".into(), } } @@ -138,7 +139,7 @@ impl WasmInstanceEnv { /// /// Returns the handle used by reducers to read from `args` /// as well as the handle used to write the error message, if any. - pub fn start_reducer(&mut self, name: &str, args: bytes::Bytes) -> (u32, u32) { + pub fn start_reducer(&mut self, name: Arc, args: bytes::Bytes) -> (u32, u32) { let errors = self.setup_standard_bytes_sink(); // Pass an invalid source when the reducer args were empty. @@ -151,7 +152,7 @@ impl WasmInstanceEnv { }; self.reducer_start = Instant::now(); - name.clone_into(&mut self.reducer_name); + self.reducer_name = name; (args, errors) }