Skip to content

Commit 907f2f9

Browse files
committed
pass configurators to NamespaceStore::new
1 parent 978dd71 commit 907f2f9

5 files changed

Lines changed: 62 additions & 31 deletions

File tree

libsql-server/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use utils::services::idle_shutdown::IdleShutdownKicker;
6060

6161
use self::config::MetaStoreConfig;
6262
use self::connection::connection_manager::InnerWalManager;
63+
use self::namespace::configurator::NamespaceConfigurators;
6364
use self::namespace::NamespaceStore;
6465
use self::net::AddrIncoming;
6566
use self::replication::script_backup_manager::{CommandHandler, ScriptBackupManager};
@@ -488,12 +489,16 @@ where
488489
meta_store_wal_manager,
489490
)
490491
.await?;
492+
493+
let configurators = NamespaceConfigurators::default();
494+
491495
let namespace_store: NamespaceStore = NamespaceStore::new(
492496
db_kind.is_replica(),
493497
self.db_config.snapshot_at_shutdown,
494498
self.max_active_namespaces,
495499
ns_config,
496500
meta_store,
501+
configurators,
497502
)
498503
.await?;
499504

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,55 @@ use futures::Future;
44

55
use super::broadcasters::BroadcasterHandle;
66
use super::meta_store::MetaStoreHandle;
7-
use super::{NamespaceConfig, NamespaceName, NamespaceStore, ResetCb, ResolveNamespacePathFn, RestoreOption};
7+
use super::{
8+
NamespaceConfig, NamespaceName, NamespaceStore, ResetCb, ResolveNamespacePathFn, RestoreOption,
9+
};
810

9-
mod replica;
1011
mod primary;
12+
mod replica;
1113
mod schema;
1214

13-
pub use replica::ReplicaConfigurator;
1415
pub use primary::PrimaryConfigurator;
16+
pub use replica::ReplicaConfigurator;
1517
pub use schema::SchemaConfigurator;
1618

1719
type DynConfigurator = dyn ConfigureNamespace + Send + Sync + 'static;
1820

19-
#[derive(Default)]
2021
pub(crate) struct NamespaceConfigurators {
2122
replica_configurator: Option<Box<DynConfigurator>>,
2223
primary_configurator: Option<Box<DynConfigurator>>,
2324
schema_configurator: Option<Box<DynConfigurator>>,
2425
}
2526

27+
impl Default for NamespaceConfigurators {
28+
fn default() -> Self {
29+
Self::empty()
30+
.with_primary(PrimaryConfigurator)
31+
.with_replica(ReplicaConfigurator)
32+
.with_schema(SchemaConfigurator)
33+
}
34+
}
35+
2636
impl NamespaceConfigurators {
27-
pub fn with_primary(
28-
&mut self,
29-
c: impl ConfigureNamespace + Send + Sync + 'static,
30-
) -> &mut Self {
37+
pub fn empty() -> Self {
38+
Self {
39+
replica_configurator: None,
40+
primary_configurator: None,
41+
schema_configurator: None,
42+
}
43+
}
44+
45+
pub fn with_primary(mut self, c: impl ConfigureNamespace + Send + Sync + 'static) -> Self {
3146
self.primary_configurator = Some(Box::new(c));
3247
self
3348
}
3449

35-
pub fn with_replica(
36-
&mut self,
37-
c: impl ConfigureNamespace + Send + Sync + 'static,
38-
) -> &mut Self {
50+
pub fn with_replica(mut self, c: impl ConfigureNamespace + Send + Sync + 'static) -> Self {
3951
self.replica_configurator = Some(Box::new(c));
4052
self
4153
}
4254

43-
pub fn with_schema(&mut self, c: impl ConfigureNamespace + Send + Sync + 'static) -> &mut Self {
55+
pub fn with_schema(mut self, c: impl ConfigureNamespace + Send + Sync + 'static) -> Self {
4456
self.schema_configurator = Some(Box::new(c));
4557
self
4658
}

libsql-server/src/namespace/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod name;
5252
pub mod replication_wal;
5353
mod schema_lock;
5454
mod store;
55-
mod configurator;
55+
pub(crate) mod configurator;
5656

5757
pub type ResetCb = Box<dyn Fn(ResetOp) + Send + Sync + 'static>;
5858
pub type ResolveNamespacePathFn =

libsql-server/src/namespace/store.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::connection::config::DatabaseConfig;
1616
use crate::database::DatabaseKind;
1717
use crate::error::Error;
1818
use crate::metrics::NAMESPACE_LOAD_LATENCY;
19-
use crate::namespace::configurator::{PrimaryConfigurator, ReplicaConfigurator, SchemaConfigurator};
2019
use crate::namespace::{NamespaceBottomlessDbId, NamespaceBottomlessDbIdInit, NamespaceName};
2120
use crate::stats::Stats;
2221

@@ -54,12 +53,13 @@ pub struct NamespaceStoreInner {
5453
}
5554

5655
impl NamespaceStore {
57-
pub async fn new(
56+
pub(crate) async fn new(
5857
allow_lazy_creation: bool,
5958
snapshot_at_shutdown: bool,
6059
max_active_namespaces: usize,
6160
config: NamespaceConfig,
6261
metadata: MetaStore,
62+
configurators: NamespaceConfigurators,
6363
) -> crate::Result<Self> {
6464
tracing::trace!("Max active namespaces: {max_active_namespaces}");
6565
let store = Cache::<NamespaceName, NamespaceEntry>::builder()
@@ -84,12 +84,6 @@ impl NamespaceStore {
8484
.time_to_idle(Duration::from_secs(86400))
8585
.build();
8686

87-
let mut configurators = NamespaceConfigurators::default();
88-
configurators
89-
.with_primary(PrimaryConfigurator)
90-
.with_replica(ReplicaConfigurator)
91-
.with_schema(SchemaConfigurator);
92-
9387
Ok(Self {
9488
inner: Arc::new(NamespaceStoreInner {
9589
store,

libsql-server/src/schema/scheduler.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ mod test {
808808

809809
use crate::connection::config::DatabaseConfig;
810810
use crate::database::DatabaseKind;
811+
use crate::namespace::configurator::{
812+
NamespaceConfigurators, PrimaryConfigurator, SchemaConfigurator,
813+
};
811814
use crate::namespace::meta_store::{metastore_connection_maker, MetaStore};
812815
use crate::namespace::{NamespaceConfig, RestoreOption};
813816
use crate::schema::SchedulerHandle;
@@ -826,9 +829,16 @@ mod test {
826829
.unwrap();
827830
let (sender, mut receiver) = mpsc::channel(100);
828831
let config = make_config(sender.clone().into(), tmp.path());
829-
let store = NamespaceStore::new(false, false, 10, config, meta_store)
830-
.await
831-
.unwrap();
832+
let store = NamespaceStore::new(
833+
false,
834+
false,
835+
10,
836+
config,
837+
meta_store,
838+
NamespaceConfigurators::default(),
839+
)
840+
.await
841+
.unwrap();
832842
let mut scheduler = Scheduler::new(store.clone(), maker().unwrap())
833843
.await
834844
.unwrap();
@@ -936,9 +946,16 @@ mod test {
936946
.unwrap();
937947
let (sender, mut receiver) = mpsc::channel(100);
938948
let config = make_config(sender.clone().into(), tmp.path());
939-
let store = NamespaceStore::new(false, false, 10, config, meta_store)
940-
.await
941-
.unwrap();
949+
let store = NamespaceStore::new(
950+
false,
951+
false,
952+
10,
953+
config,
954+
meta_store,
955+
NamespaceConfigurators::default(),
956+
)
957+
.await
958+
.unwrap();
942959
let mut scheduler = Scheduler::new(store.clone(), maker().unwrap())
943960
.await
944961
.unwrap();
@@ -1012,7 +1029,7 @@ mod test {
10121029
.unwrap();
10131030
let (sender, _receiver) = mpsc::channel(100);
10141031
let config = make_config(sender.clone().into(), tmp.path());
1015-
let store = NamespaceStore::new(false, false, 10, config, meta_store)
1032+
let store = NamespaceStore::new(false, false, 10, config, meta_store, NamespaceConfigurators::default())
10161033
.await
10171034
.unwrap();
10181035

@@ -1039,7 +1056,10 @@ mod test {
10391056
.unwrap();
10401057
let (sender, mut receiver) = mpsc::channel(100);
10411058
let config = make_config(sender.clone().into(), tmp.path());
1042-
let store = NamespaceStore::new(false, false, 10, config, meta_store)
1059+
let configurators = NamespaceConfigurators::default()
1060+
.with_schema(SchemaConfigurator)
1061+
.with_primary(PrimaryConfigurator);
1062+
let store = NamespaceStore::new(false, false, 10, config, meta_store, configurators)
10431063
.await
10441064
.unwrap();
10451065
let mut scheduler = Scheduler::new(store.clone(), maker().unwrap())
@@ -1112,7 +1132,7 @@ mod test {
11121132
.unwrap();
11131133
let (sender, _receiver) = mpsc::channel(100);
11141134
let config = make_config(sender.clone().into(), tmp.path());
1115-
let store = NamespaceStore::new(false, false, 10, config, meta_store)
1135+
let store = NamespaceStore::new(false, false, 10, config, meta_store, NamespaceConfigurators::default())
11161136
.await
11171137
.unwrap();
11181138
let scheduler = Scheduler::new(store.clone(), maker().unwrap())

0 commit comments

Comments
 (0)