@@ -9,6 +9,7 @@ use bytes::Bytes;
9
9
use enclose:: enclose;
10
10
use futures:: Stream ;
11
11
use libsql_sys:: wal:: Sqlite3WalManager ;
12
+ use libsql_sys:: EncryptionConfig ;
12
13
use tokio:: io:: AsyncBufReadExt as _;
13
14
use tokio:: sync:: watch;
14
15
use tokio:: task:: JoinSet ;
@@ -49,6 +50,7 @@ pub(super) async fn make_primary_connection_maker(
49
50
resolve_attach_path : ResolveNamespacePathFn ,
50
51
broadcaster : BroadcasterHandle ,
51
52
make_wal_manager : Arc < dyn Fn ( ) -> InnerWalManager + Sync + Send + ' static > ,
53
+ encryption_config : Option < EncryptionConfig > ,
52
54
) -> crate :: Result < ( PrimaryConnectionMaker , ReplicationWalWrapper , Arc < Stats > ) > {
53
55
let db_config = meta_store_handle. get ( ) ;
54
56
let bottomless_db_id = NamespaceBottomlessDbId :: from_config ( & db_config) ;
@@ -102,7 +104,7 @@ pub(super) async fn make_primary_connection_maker(
102
104
auto_checkpoint,
103
105
primary_config. scripted_backup . clone ( ) ,
104
106
name. clone ( ) ,
105
- None ,
107
+ encryption_config . clone ( ) ,
106
108
) ?) ;
107
109
108
110
tracing:: debug!( "sending stats" ) ;
@@ -114,6 +116,7 @@ pub(super) async fn make_primary_connection_maker(
114
116
base_config. stats_sender . clone ( ) ,
115
117
name. clone ( ) ,
116
118
logger. new_frame_notifier . subscribe ( ) ,
119
+ base_config. encryption_config . clone ( ) ,
117
120
)
118
121
. await ?;
119
122
@@ -133,7 +136,7 @@ pub(super) async fn make_primary_connection_maker(
133
136
base_config. max_total_response_size ,
134
137
auto_checkpoint,
135
138
logger. new_frame_notifier . subscribe ( ) ,
136
- None ,
139
+ encryption_config ,
137
140
block_writes,
138
141
resolve_attach_path,
139
142
make_wal_manager. clone ( ) ,
@@ -332,6 +335,7 @@ pub(super) async fn make_stats(
332
335
stats_sender : StatsSender ,
333
336
name : NamespaceName ,
334
337
mut current_frame_no : watch:: Receiver < Option < FrameNo > > ,
338
+ encryption_config : Option < EncryptionConfig > ,
335
339
) -> anyhow:: Result < Arc < Stats > > {
336
340
tracing:: debug!( "creating stats type" ) ;
337
341
let stats = Stats :: new ( name. clone ( ) , db_path, join_set) . await ?;
@@ -358,7 +362,11 @@ pub(super) async fn make_stats(
358
362
}
359
363
} ) ;
360
364
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
+ ) ) ;
362
370
363
371
tracing:: debug!( "done sending stats, and creating bg tasks" ) ;
364
372
@@ -368,7 +376,11 @@ pub(super) async fn make_stats(
368
376
// Periodically check the storage used by the database and save it in the Stats structure.
369
377
// TODO: Once we have a separate fiber that does WAL checkpoints, running this routine
370
378
// 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 < ( ) > {
372
384
// on initialization, the database file doesn't exist yet, so we wait a bit for it to be
373
385
// created
374
386
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
381
393
return Ok ( ( ) ) ;
382
394
} ;
383
395
396
+ let encryption_config = encryption_config. clone ( ) ;
384
397
let _ = tokio:: task:: spawn_blocking ( move || {
385
398
// because closing the last connection interferes with opening a new one, we lazily
386
399
// initialize a connection here, and keep it alive for the entirety of the program. If we
387
400
// 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 ) {
389
402
Ok ( mut conn) => {
390
403
if let Ok ( tx) = conn. transaction ( ) {
391
404
let page_count = tx. query_row ( "pragma page_count;" , [ ] , |row| { row. get :: < usize , u64 > ( 0 ) } ) ;
0 commit comments