@@ -9,6 +9,7 @@ use bytes::Bytes;
99use enclose:: enclose;
1010use futures:: Stream ;
1111use libsql_sys:: wal:: Sqlite3WalManager ;
12+ use libsql_sys:: EncryptionConfig ;
1213use tokio:: io:: AsyncBufReadExt as _;
1314use tokio:: sync:: watch;
1415use tokio:: task:: JoinSet ;
@@ -49,6 +50,7 @@ pub(super) async fn make_primary_connection_maker(
4950 resolve_attach_path : ResolveNamespacePathFn ,
5051 broadcaster : BroadcasterHandle ,
5152 make_wal_manager : Arc < dyn Fn ( ) -> InnerWalManager + Sync + Send + ' static > ,
53+ encryption_config : Option < EncryptionConfig > ,
5254) -> crate :: Result < ( PrimaryConnectionMaker , ReplicationWalWrapper , Arc < Stats > ) > {
5355 let db_config = meta_store_handle. get ( ) ;
5456 let bottomless_db_id = NamespaceBottomlessDbId :: from_config ( & db_config) ;
@@ -102,7 +104,7 @@ pub(super) async fn make_primary_connection_maker(
102104 auto_checkpoint,
103105 primary_config. scripted_backup . clone ( ) ,
104106 name. clone ( ) ,
105- None ,
107+ encryption_config . clone ( ) ,
106108 ) ?) ;
107109
108110 tracing:: debug!( "sending stats" ) ;
@@ -114,6 +116,7 @@ pub(super) async fn make_primary_connection_maker(
114116 base_config. stats_sender . clone ( ) ,
115117 name. clone ( ) ,
116118 logger. new_frame_notifier . subscribe ( ) ,
119+ base_config. encryption_config . clone ( ) ,
117120 )
118121 . await ?;
119122
@@ -133,7 +136,7 @@ pub(super) async fn make_primary_connection_maker(
133136 base_config. max_total_response_size ,
134137 auto_checkpoint,
135138 logger. new_frame_notifier . subscribe ( ) ,
136- None ,
139+ encryption_config ,
137140 block_writes,
138141 resolve_attach_path,
139142 make_wal_manager. clone ( ) ,
@@ -332,6 +335,7 @@ pub(super) async fn make_stats(
332335 stats_sender : StatsSender ,
333336 name : NamespaceName ,
334337 mut current_frame_no : watch:: Receiver < Option < FrameNo > > ,
338+ encryption_config : Option < EncryptionConfig > ,
335339) -> anyhow:: Result < Arc < Stats > > {
336340 tracing:: debug!( "creating stats type" ) ;
337341 let stats = Stats :: new ( name. clone ( ) , db_path, join_set) . await ?;
@@ -358,7 +362,11 @@ pub(super) async fn make_stats(
358362 }
359363 } ) ;
360364
361- join_set. spawn ( run_storage_monitor ( db_path. into ( ) , Arc :: downgrade ( & stats) ) ) ;
365+ join_set. spawn ( run_storage_monitor (
366+ db_path. into ( ) ,
367+ Arc :: downgrade ( & stats) ,
368+ encryption_config,
369+ ) ) ;
362370
363371 tracing:: debug!( "done sending stats, and creating bg tasks" ) ;
364372
@@ -368,7 +376,11 @@ pub(super) async fn make_stats(
368376// Periodically check the storage used by the database and save it in the Stats structure.
369377// TODO: Once we have a separate fiber that does WAL checkpoints, running this routine
370378// right after checkpointing is exactly where it should be done.
371- async fn run_storage_monitor ( db_path : PathBuf , stats : Weak < Stats > ) -> anyhow:: Result < ( ) > {
379+ async fn run_storage_monitor (
380+ db_path : PathBuf ,
381+ stats : Weak < Stats > ,
382+ encryption_config : Option < EncryptionConfig > ,
383+ ) -> anyhow:: Result < ( ) > {
372384 // on initialization, the database file doesn't exist yet, so we wait a bit for it to be
373385 // created
374386 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
@@ -381,11 +393,12 @@ async fn run_storage_monitor(db_path: PathBuf, stats: Weak<Stats>) -> anyhow::Re
381393 return Ok ( ( ) ) ;
382394 } ;
383395
396+ let encryption_config = encryption_config. clone ( ) ;
384397 let _ = tokio:: task:: spawn_blocking ( move || {
385398 // because closing the last connection interferes with opening a new one, we lazily
386399 // initialize a connection here, and keep it alive for the entirety of the program. If we
387400 // fail to open it, we wait for `duration` and try again later.
388- match open_conn ( & db_path, Sqlite3WalManager :: new ( ) , Some ( rusqlite:: OpenFlags :: SQLITE_OPEN_READ_ONLY ) , None ) {
401+ match open_conn ( & db_path, Sqlite3WalManager :: new ( ) , Some ( rusqlite:: OpenFlags :: SQLITE_OPEN_READ_ONLY ) , encryption_config ) {
389402 Ok ( mut conn) => {
390403 if let Ok ( tx) = conn. transaction ( ) {
391404 let page_count = tx. query_row ( "pragma page_count;" , [ ] , |row| { row. get :: < usize , u64 > ( 0 ) } ) ;
0 commit comments