Skip to content

Commit 6895ebe

Browse files
committed
more comments
1 parent df53e68 commit 6895ebe

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

crates/core/src/host/host_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl HostController {
357357
});
358358

359359
let db = module.replica_ctx().relational_db.clone();
360-
let result = module.on_module_thread("using_database", move || f(db)).await?.await;
360+
let result = module.on_module_thread_async("using_database", move || f(db)).await?;
361361
Ok(result)
362362
}
363363
/// Update the [`ModuleHost`] identified by `replica_id` to the given

crates/core/src/host/module_host.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,10 @@ pub struct CallViewParams {
543543
pub caller_connection_id: Option<ConnectionId>,
544544
pub view_id: ViewId,
545545
pub args: ArgsTuple,
546-
/// The expected return type of the view, used for deserialization.
547-
/// This type information is obtained from the [`ModuleDef`].
546+
547+
/// The return type of the view, used for deserializing the view call result.
548+
/// Either Option<T>`, or `Vec<T>` where `T` is a `ProductType`.
549+
/// This type information is obtained from the [`ModuleDef`]
548550
pub return_type: AlgebraicType,
549551
/// Whether the view is being called anonymously (i.e., without a client identity).
550552
pub is_anonymous: bool,
@@ -843,6 +845,29 @@ impl ModuleHost {
843845
Ok(res)
844846
}
845847

848+
/// Run an async function on the JobThread for this module.
849+
/// Similar to `on_module_thread`, but for async functions.
850+
pub async fn on_module_thread_async<Fun, Fut, R>(&self, label: &str, f: Fun) -> Result<R, anyhow::Error>
851+
where
852+
Fun: (FnOnce() -> Fut) + Send + 'static,
853+
Fut: Future<Output = R> + Send + 'static,
854+
R: Send + 'static,
855+
{
856+
self.guard_closed()?;
857+
858+
let timer_guard = self.start_call_timer(label);
859+
860+
let res = self
861+
.executor
862+
.run_job(async move {
863+
drop(timer_guard);
864+
f().await
865+
})
866+
.await;
867+
868+
Ok(res)
869+
}
870+
846871
fn start_call_timer(&self, label: &str) -> ScopeGuard<(), impl FnOnce(())> {
847872
// Record the time until our function starts running.
848873
let queue_timer = WORKER_METRICS
@@ -869,7 +894,7 @@ impl ModuleHost {
869894
})
870895
}
871896

872-
async fn call_async_with_instance<Fun, Fut, R>(&self, label: &str, f: Fun) -> Result<R, NoSuchModule>
897+
pub async fn call_async_with_instance<Fun, Fut, R>(&self, label: &str, f: Fun) -> Result<R, NoSuchModule>
873898
where
874899
Fun: (FnOnce(Instance) -> Fut) + Send + 'static,
875900
Fut: Future<Output = (R, Instance)> + Send + 'static,

crates/core/src/sql/execute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ pub async fn run(
204204
let mut metrics = ExecutionMetrics::default();
205205

206206
for (view_name, args) in stmt.views() {
207-
let (is_memoized, args) = tx
207+
let (is_materialized, args) = tx
208208
.is_materialized(view_name, args, caller_identity)
209209
.map_err(|e| DBError::Other(anyhow!("Failed to check memoized view: {e}")))?;
210210

211211
// Skip if already memoized
212-
if is_memoized {
212+
if is_materialized {
213213
continue;
214214
}
215215

crates/datastore/src/locking_tx_datastore/committed_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,11 @@ impl CommittedState {
738738
}
739739
}
740740

741-
fn merge_read_sets(&mut self, read_sets: ViewReadSets, tables: impl IntoIterator<Item = TableId>) {
741+
fn merge_read_sets(&mut self, read_sets: ViewReadSets, updated_tables: impl IntoIterator<Item = TableId>) {
742742
for (view, read_set) in read_sets {
743743
self.merge_read_set(view, read_set);
744744
}
745-
for table_id in tables {
745+
for table_id in updated_tables {
746746
self.read_sets.clear_views_for_table(table_id);
747747
}
748748
}

crates/datastore/src/locking_tx_datastore/mut_tx.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ use super::{
88
tx_state::{IndexIdMap, PendingSchemaChange, TxState, TxTableForInsertion},
99
SharedMutexGuard, SharedWriteGuard,
1010
};
11-
use crate::traits::{InsertFlags, RowTypeForTable, TxData, UpdateFlags};
12-
use crate::{
13-
error::ViewError,
14-
system_tables::{
15-
system_tables, ConnectionIdViaU128, IdentityViaU256, StConnectionCredentialsFields, StConnectionCredentialsRow,
16-
StViewArgFields, StViewArgRow, StViewClientRow, StViewColumnFields, StViewFields, StViewParamFields,
17-
StViewParamRow, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_ARG_ID, ST_VIEW_CLIENT_ID, ST_VIEW_COLUMN_ID, ST_VIEW_ID,
18-
ST_VIEW_PARAM_ID,
19-
},
11+
use crate::system_tables::{
12+
system_tables, ConnectionIdViaU128, IdentityViaU256, StConnectionCredentialsFields, StConnectionCredentialsRow,
13+
StViewArgFields, StViewArgRow, StViewColumnFields, StViewFields, StViewParamFields, StViewParamRow,
14+
StViewSubFields, StViewSubRow, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_ARG_ID, ST_VIEW_COLUMN_ID, ST_VIEW_ID,
15+
ST_VIEW_PARAM_ID, ST_VIEW_SUB_ID,
2016
};
17+
use crate::traits::{InsertFlags, RowTypeForTable, TxData, UpdateFlags};
2118
use crate::{
2219
error::{IndexError, SequenceError, TableError},
2320
system_tables::{
@@ -740,7 +737,7 @@ impl MutTxId {
740737
Ok((tx, commit))
741738
}
742739

743-
/// Checks whether a memoized view exists for the given view name, arguments, and sender identity.
740+
/// Checks whether a materialized view exists for the given view name, arguments, and sender identity.
744741
///
745742
/// If view is not materialized, [`RelationalDB::evaluate_view`] should be called to compute and store it.
746743
///

0 commit comments

Comments
 (0)