@@ -13,7 +13,9 @@ use spacetimedb::config::{CertificateAuthority, MetadataFile};
1313use spacetimedb:: db;
1414use spacetimedb:: db:: persistence:: LocalPersistenceProvider ;
1515use spacetimedb:: energy:: { EnergyBalance , EnergyQuanta , NullEnergyMonitor } ;
16- use spacetimedb:: host:: { DiskStorage , HostController , MigratePlanResult , UpdateDatabaseResult } ;
16+ use spacetimedb:: host:: {
17+ DiskStorage , HostController , MemoryStorage , MigratePlanResult , ProgramStorage , UpdateDatabaseResult ,
18+ } ;
1719use spacetimedb:: identity:: { AuthCtx , Identity } ;
1820use spacetimedb:: messages:: control_db:: { Database , Node , Replica } ;
1921use spacetimedb:: util:: jobs:: JobCores ;
@@ -41,11 +43,11 @@ pub struct StandaloneOptions {
4143
4244pub struct StandaloneEnv {
4345 control_db : ControlDb ,
44- program_store : Arc < DiskStorage > ,
46+ program_store : ProgramStorage ,
4547 host_controller : HostController ,
4648 client_actor_index : ClientActorIndex ,
4749 metrics_registry : prometheus:: Registry ,
48- _pid_file : PidFile ,
50+ _pid_file : Option < PidFile > ,
4951 auth_provider : auth:: DefaultJwtAuthProvider ,
5052 websocket_options : WebSocketOptions ,
5153}
@@ -57,17 +59,24 @@ impl StandaloneEnv {
5759 data_dir : Arc < ServerDataDir > ,
5860 db_cores : JobCores ,
5961 ) -> anyhow:: Result < Arc < Self > > {
60- let _pid_file = data_dir. pid_file ( ) ?;
61- let meta_path = data_dir. metadata_toml ( ) ;
62- let mut meta = MetadataFile :: new ( "standalone" ) ;
63- if let Some ( existing_meta) = MetadataFile :: read ( & meta_path) . context ( "failed reading metadata.toml" ) ? {
64- meta = existing_meta. check_compatibility_and_update ( meta) ?;
65- }
66- meta. write ( & meta_path) . context ( "failed writing metadata.toml" ) ?;
62+ let ( pid_file, control_db, program_store) : ( Option < PidFile > , ControlDb , ProgramStorage ) =
63+ if config. db_config . storage == db:: Storage :: Disk {
64+ let meta_path = data_dir. metadata_toml ( ) ;
65+ let mut meta = MetadataFile :: new ( "standalone" ) ;
66+ if let Some ( existing_meta) = MetadataFile :: read ( & meta_path) . context ( "failed reading metadata.toml" ) ? {
67+ meta = existing_meta. check_compatibility_and_update ( meta) ?;
68+ }
69+ meta. write ( & meta_path) . context ( "failed writing metadata.toml" ) ?;
70+ let control_db = ControlDb :: new ( & data_dir. control_db ( ) ) . context ( "failed to initialize control db" ) ?;
71+ let program_store = Arc :: new ( DiskStorage :: new ( data_dir. program_bytes ( ) . 0 ) . await ?) ;
72+ ( Some ( data_dir. pid_file ( ) ?) , control_db, program_store)
73+ } else {
74+ let control_db = ControlDb :: new_in_memory ( ) . context ( "failed to initialize in-memory control db" ) ?;
75+ let program_store = Arc :: new ( MemoryStorage :: new ( ) . await ?) ;
76+ ( None , control_db, program_store)
77+ } ;
6778
68- let control_db = ControlDb :: new ( & data_dir. control_db ( ) ) . context ( "failed to initialize control db" ) ?;
6979 let energy_monitor = Arc :: new ( NullEnergyMonitor ) ;
70- let program_store = Arc :: new ( DiskStorage :: new ( data_dir. program_bytes ( ) . 0 ) . await ?) ;
7180
7281 let persistence_provider = Arc :: new ( LocalPersistenceProvider :: new ( data_dir. clone ( ) ) ) ;
7382 let host_controller = HostController :: new (
@@ -94,7 +103,7 @@ impl StandaloneEnv {
94103 host_controller,
95104 client_actor_index,
96105 metrics_registry,
97- _pid_file,
106+ _pid_file : pid_file ,
98107 auth_provider : auth_env,
99108 websocket_options : config. websocket ,
100109 } ) )
0 commit comments