Skip to content

Commit 6e7fb9f

Browse files
committed
restore encryption config
we don't actually care, but let's do it for completeness
1 parent e5b8c31 commit 6e7fb9f

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

libsql-server/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ where
458458
max_total_response_size: self.db_config.max_total_response_size,
459459
max_concurrent_connections: Arc::new(Semaphore::new(self.max_concurrent_connections)),
460460
max_concurrent_requests: self.db_config.max_concurrent_requests,
461+
encryption_config: self.db_config.encryption_config.clone(),
461462
};
462463

463464
let configurators = self

libsql-server/src/namespace/configurator/helpers.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use bytes::Bytes;
99
use enclose::enclose;
1010
use futures::Stream;
1111
use libsql_sys::wal::Sqlite3WalManager;
12+
use libsql_sys::EncryptionConfig;
1213
use tokio::io::AsyncBufReadExt as _;
1314
use tokio::sync::watch;
1415
use 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) });

libsql-server/src/namespace/configurator/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Duration;
55

66
use chrono::NaiveDateTime;
77
use futures::Future;
8+
use libsql_sys::EncryptionConfig;
89
use tokio::sync::Semaphore;
910

1011
use crate::connection::config::DatabaseConfig;
@@ -38,6 +39,7 @@ pub struct BaseNamespaceConfig {
3839
pub(crate) max_total_response_size: u64,
3940
pub(crate) max_concurrent_connections: Arc<Semaphore>,
4041
pub(crate) max_concurrent_requests: u64,
42+
pub(crate) encryption_config: Option<EncryptionConfig>,
4143
}
4244

4345
#[derive(Clone)]

libsql-server/src/namespace/configurator/primary.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
use std::path::Path;
2+
use std::pin::Pin;
13
use std::sync::atomic::{AtomicBool, Ordering};
2-
use std::{path::Path, pin::Pin, sync::Arc};
4+
use std::sync::Arc;
35

46
use futures::prelude::Future;
7+
use libsql_sys::EncryptionConfig;
58
use tokio::task::JoinSet;
69

710
use crate::connection::config::DatabaseConfig;
@@ -49,6 +52,7 @@ impl PrimaryConfigurator {
4952
resolve_attach_path: ResolveNamespacePathFn,
5053
db_path: Arc<Path>,
5154
broadcaster: BroadcasterHandle,
55+
encryption_config: Option<EncryptionConfig>,
5256
) -> crate::Result<Namespace> {
5357
let mut join_set = JoinSet::new();
5458

@@ -67,6 +71,7 @@ impl PrimaryConfigurator {
6771
resolve_attach_path,
6872
broadcaster,
6973
self.make_wal_manager.clone(),
74+
encryption_config,
7075
)
7176
.await?;
7277
let connection_maker = Arc::new(connection_maker);
@@ -135,6 +140,7 @@ impl ConfigureNamespace for PrimaryConfigurator {
135140
resolve_attach_path,
136141
db_path.clone(),
137142
broadcaster,
143+
self.base.encryption_config.clone(),
138144
)
139145
.await
140146
{

libsql-server/src/namespace/configurator/replica.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl ConfigureNamespace for ReplicaConfigurator {
169169
self.base.stats_sender.clone(),
170170
name.clone(),
171171
applied_frame_no_receiver.clone(),
172+
self.base.encryption_config.clone(),
172173
)
173174
.await?;
174175

libsql-server/src/namespace/configurator/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl ConfigureNamespace for SchemaConfigurator {
6868
resolve_attach_path,
6969
broadcaster,
7070
self.make_wal_manager.clone(),
71+
self.base.encryption_config.clone(),
7172
)
7273
.await?;
7374

libsql-server/src/schema/scheduler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ mod test {
917917
max_total_response_size: 100000000000,
918918
max_concurrent_connections: Arc::new(Semaphore::new(10)),
919919
max_concurrent_requests: 10000,
920+
encryption_config: None,
920921
};
921922

922923
let primary_config = PrimaryExtraConfig {

0 commit comments

Comments
 (0)