Skip to content

Commit ce2ba55

Browse files
committed
add V8Runtime skeleton + HostType::Js
1 parent c3cfadb commit ce2ba55

6 files changed

Lines changed: 109 additions & 8 deletions

File tree

crates/core/src/db/datastore/system_tables.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,15 @@ pub struct ModuleKind(u8);
816816
impl ModuleKind {
817817
/// The [`ModuleKind`] of WASM-based modules.
818818
pub const WASM: ModuleKind = ModuleKind(0);
819+
/// The [`ModuleKind`] of JS modules.
820+
pub const JS: ModuleKind = ModuleKind(1);
819821
}
820822

821823
impl From<crate::messages::control_db::HostType> for ModuleKind {
822824
fn from(host_type: crate::messages::control_db::HostType) -> Self {
823825
match host_type {
824826
crate::messages::control_db::HostType::Wasm => Self::WASM,
827+
crate::messages::control_db::HostType::Js => Self::JS,
825828
}
826829
}
827830
}

crates/core/src/host/host_controller.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::db::db_metrics::DB_METRICS;
99
use crate::db::relational_db::{self, DiskSizeFn, RelationalDB, Txdata};
1010
use crate::db::{self, spawn_tx_metrics_recorder};
1111
use crate::energy::{EnergyMonitor, EnergyQuanta, NullEnergyMonitor};
12+
use crate::host::v8::V8Runtime;
1213
use crate::messages::control_db::{Database, HostType};
1314
use crate::module_host_context::ModuleCreationContext;
1415
use crate::replica_context::ReplicaContext;
@@ -106,12 +107,14 @@ pub struct HostController {
106107

107108
struct HostRuntimes {
108109
wasmtime: WasmtimeRuntime,
110+
v8: V8Runtime,
109111
}
110112

111113
impl HostRuntimes {
112114
fn new(data_dir: Option<&ServerDataDir>) -> Arc<Self> {
113115
let wasmtime = WasmtimeRuntime::new(data_dir);
114-
Arc::new(Self { wasmtime })
116+
let v8 = V8Runtime::new();
117+
Arc::new(Self { wasmtime, v8 })
115118
}
116119
}
117120

@@ -671,19 +674,25 @@ async fn make_module_host(
671674
// threads, but those aren't for computation. Also, wasmtime uses rayon
672675
// to run compilation in parallel, so it'll need to run stuff in rayon anyway.
673676
asyncify(move || {
677+
let mcc = ModuleCreationContext {
678+
replica_ctx,
679+
scheduler,
680+
program: &program,
681+
energy_monitor,
682+
};
683+
684+
let start = Instant::now();
674685
let module_host = match host_type {
675686
HostType::Wasm => {
676-
let mcc = ModuleCreationContext {
677-
replica_ctx,
678-
scheduler,
679-
program: &program,
680-
energy_monitor,
681-
};
682-
let start = Instant::now();
683687
let actor = runtimes.wasmtime.make_actor(mcc)?;
684688
trace!("wasmtime::make_actor blocked for {:?}", start.elapsed());
685689
ModuleHost::new(actor, unregister, core)
686690
}
691+
HostType::Js => {
692+
let actor = runtimes.v8.make_actor(mcc)?;
693+
trace!("v8::make_actor blocked for {:?}", start.elapsed());
694+
ModuleHost::new(actor, unregister, core)
695+
}
687696
};
688697
Ok((program, module_host))
689698
})

crates/core/src/host/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ mod host_controller;
1616
pub mod module_host;
1717
pub mod scheduler;
1818
pub mod wasmtime;
19+
1920
// Visible for integration testing.
2021
pub mod instance_env;
22+
pub mod v8; // only pub for testing
2123
mod wasm_common;
2224

2325
pub use disk_storage::DiskStorage;

crates/core/src/host/v8/mod.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use crate::{
2+
db::datastore::locking_tx_datastore::MutTxId,
3+
host::{
4+
module_host::{DynModule, Module, ModuleInfo, ModuleInstance},
5+
Scheduler,
6+
},
7+
module_host_context::ModuleCreationContext,
8+
replica_context::ReplicaContext,
9+
};
10+
use anyhow::anyhow;
11+
use std::sync::{Arc, Once};
12+
13+
use super::module_host::CallReducerParams;
14+
15+
pub struct V8Runtime {
16+
_priv: (),
17+
}
18+
19+
impl V8Runtime {
20+
#[allow(clippy::new_without_default)]
21+
pub fn new() -> Self {
22+
static V8_INIT: Once = Once::new();
23+
V8_INIT.call_once(|| {
24+
// TODO
25+
});
26+
27+
Self { _priv: () }
28+
}
29+
30+
pub fn make_actor(&self, _: ModuleCreationContext<'_>) -> anyhow::Result<impl Module> {
31+
Err::<JsModule, _>(anyhow!("v8_todo"))
32+
}
33+
}
34+
35+
#[derive(Clone)]
36+
struct JsModule;
37+
38+
impl DynModule for JsModule {
39+
fn replica_ctx(&self) -> &Arc<ReplicaContext> {
40+
todo!()
41+
}
42+
43+
fn scheduler(&self) -> &Scheduler {
44+
todo!()
45+
}
46+
}
47+
48+
impl Module for JsModule {
49+
type Instance = JsInstance;
50+
51+
type InitialInstances<'a> = std::iter::Empty<JsInstance>;
52+
53+
fn initial_instances(&mut self) -> Self::InitialInstances<'_> {
54+
std::iter::empty()
55+
}
56+
57+
fn info(&self) -> Arc<ModuleInfo> {
58+
todo!()
59+
}
60+
61+
fn create_instance(&self) -> Self::Instance {
62+
todo!()
63+
}
64+
}
65+
66+
struct JsInstance;
67+
68+
impl ModuleInstance for JsInstance {
69+
fn trapped(&self) -> bool {
70+
todo!()
71+
}
72+
73+
fn update_database(
74+
&mut self,
75+
_program: crate::db::datastore::traits::Program,
76+
_old_module_info: Arc<ModuleInfo>,
77+
) -> anyhow::Result<super::UpdateDatabaseResult> {
78+
todo!()
79+
}
80+
81+
fn call_reducer(&mut self, _tx: Option<MutTxId>, _params: CallReducerParams) -> super::ReducerCallResult {
82+
todo!()
83+
}
84+
}

crates/core/src/messages/control_db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ pub struct NodeStatus {
7474
#[repr(i32)]
7575
pub enum HostType {
7676
Wasm = 0,
77+
Js,
7778
}

crates/standalone/src/subcommands/extract_schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ struct Args {
2222
#[derive(clap::ValueEnum, Copy, Clone)]
2323
enum HostType {
2424
Wasm,
25+
Js,
2526
}
2627

2728
impl From<HostType> for control_db::HostType {
2829
fn from(x: HostType) -> Self {
2930
match x {
3031
HostType::Wasm => control_db::HostType::Wasm,
32+
HostType::Js => control_db::HostType::Js,
3133
}
3234
}
3335
}

0 commit comments

Comments
 (0)