Extend WasmInstance with methods for calling views.
|
pub trait WasmInstance: Send + Sync + 'static { |
|
fn extract_descriptions(&mut self) -> Result<Vec<u8>, DescribeError>; |
|
|
|
fn instance_env(&self) -> &InstanceEnv; |
|
|
|
fn call_reducer(&mut self, op: ReducerOp<'_>, budget: ReducerBudget) -> ExecuteResult; |
|
|
|
fn log_traceback(func_type: &str, func: &str, trap: &anyhow::Error); |
|
} |
This is necessary in order to be able to call views from the query engine. As such, it would be helpful if, as part of this ticket, we made it possible to call into a WasmInstance from the query engine.
Note that while views do not return Results, they can panic. Hence this interface should handle WASM traps so that we can return such errors to clients and subsequently disconnect clients.
We need an interface for the following contexts:
SQL (http/remote query):
This is a read only context. A view in this context can still use a mutable transaction, but it won't update any internal state. It can either fully evaluate the view every time, or it can check if it has a backing table and scan that.
Subscribe:
A view in this context will run in a mutable transaction. If already subscribed to and materialized, it should just return the materialized results. Otherwise we should:
- Update
st_view_arg if necessary
- Update
st_view_client
- Evaluate the view
- Update read sets and backing table
- Return result
Unsubscribe:
A view in this context will run in a mutable transaction. The client is already subscribed so we know the result set is materialized. We should:
- Scan and return the materialized result
- Drop the materialized result (delete rows from the backing table)
- Update
st_view_client (remove subscriber)
- Update
st_view_arg potentially (if no one is subscribed to this set of args)
Subscription Update:
A view in this context will run in a mutable transaction. When evaluating a view in this context, we have already checked and determined that the view is stale, hence we are always evaluating the view (not reading cached results) and updating its read set. We also must update the backing table in this case. Note that technically it is not necessary to return the result of the view to the caller because in this case the caller only cares about the table diff which it will get when downgrading the transaction before dispatching to the subscription engine.
Extend
WasmInstancewith methods for calling views.SpacetimeDB/crates/core/src/host/wasm_common/module_host_actor.rs
Lines 51 to 59 in a952ba5
This is necessary in order to be able to call views from the query engine. As such, it would be helpful if, as part of this ticket, we made it possible to call into a
WasmInstancefrom the query engine.Note that while views do not return
Results, they canpanic. Hence this interface should handle WASM traps so that we can return such errors to clients and subsequently disconnect clients.We need an interface for the following contexts:
SQL (http/remote query):
This is a read only context. A view in this context can still use a mutable transaction, but it won't update any internal state. It can either fully evaluate the view every time, or it can check if it has a backing table and scan that.
Subscribe:
A view in this context will run in a mutable transaction. If already subscribed to and materialized, it should just return the materialized results. Otherwise we should:
st_view_argif necessaryst_view_clientUnsubscribe:
A view in this context will run in a mutable transaction. The client is already subscribed so we know the result set is materialized. We should:
st_view_client(remove subscriber)st_view_argpotentially (if no one is subscribed to this set of args)Subscription Update:
A view in this context will run in a mutable transaction. When evaluating a view in this context, we have already checked and determined that the view is stale, hence we are always evaluating the view (not reading cached results) and updating its read set. We also must update the backing table in this case. Note that technically it is not necessary to return the result of the view to the caller because in this case the caller only cares about the table diff which it will get when downgrading the transaction before dispatching to the subscription engine.