diff --git a/crates/index-scheduler/src/features.rs b/crates/index-scheduler/src/features.rs index 43101560a..3049479df 100644 --- a/crates/index-scheduler/src/features.rs +++ b/crates/index-scheduler/src/features.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use meilisearch_types::features::{InstanceTogglableFeatures, RuntimeTogglableFeatures}; +use meilisearch_types::features::{InstanceTogglableFeatures, Network, RuntimeTogglableFeatures}; use meilisearch_types::heed::types::{SerdeJson, Str}; use meilisearch_types::heed::{Database, Env, RwTxn}; @@ -14,10 +14,16 @@ mod db_name { pub const EXPERIMENTAL_FEATURES: &str = "experimental-features"; } +mod db_keys { + pub const EXPERIMENTAL_FEATURES: &str = "experimental-features"; + pub const NETWORK: &str = "network"; +} + #[derive(Clone)] pub(crate) struct FeatureData { persisted: Database>, runtime: Arc>, + network: Arc>, } #[derive(Debug, Clone, Copy)] @@ -115,7 +121,7 @@ impl FeatureData { env.create_database(wtxn, Some(db_name::EXPERIMENTAL_FEATURES))?; let persisted_features: RuntimeTogglableFeatures = - runtime_features_db.get(wtxn, db_name::EXPERIMENTAL_FEATURES)?.unwrap_or_default(); + runtime_features_db.get(wtxn, db_keys::EXPERIMENTAL_FEATURES)?.unwrap_or_default(); let InstanceTogglableFeatures { metrics, logs_route, contains_filter } = instance_features; let runtime = Arc::new(RwLock::new(RuntimeTogglableFeatures { metrics: metrics || persisted_features.metrics, @@ -124,7 +130,14 @@ impl FeatureData { ..persisted_features })); - Ok(Self { persisted: runtime_features_db, runtime }) + let network_db = runtime_features_db.remap_data_type::>(); + let network: Network = network_db.get(wtxn, db_keys::NETWORK)?.unwrap_or_default(); + + Ok(Self { + persisted: runtime_features_db, + runtime, + network: Arc::new(RwLock::new(network)), + }) } pub fn put_runtime_features( @@ -132,7 +145,7 @@ impl FeatureData { mut wtxn: RwTxn, features: RuntimeTogglableFeatures, ) -> Result<()> { - self.persisted.put(&mut wtxn, db_name::EXPERIMENTAL_FEATURES, &features)?; + self.persisted.put(&mut wtxn, db_keys::EXPERIMENTAL_FEATURES, &features)?; wtxn.commit()?; // safe to unwrap, the lock will only fail if: @@ -153,4 +166,21 @@ impl FeatureData { pub fn features(&self) -> RoFeatures { RoFeatures::new(self) } + + pub fn put_network(&self, mut wtxn: RwTxn, new_network: Network) -> Result<()> { + self.persisted.remap_data_type::>().put( + &mut wtxn, + db_keys::NETWORK, + &new_network, + )?; + wtxn.commit()?; + + let mut network = self.network.write().unwrap(); + *network = new_network; + Ok(()) + } + + pub fn network(&self) -> Network { + Network::clone(&*self.network.read().unwrap()) + } } diff --git a/crates/index-scheduler/src/lib.rs b/crates/index-scheduler/src/lib.rs index 530b7bedc..0f8212470 100644 --- a/crates/index-scheduler/src/lib.rs +++ b/crates/index-scheduler/src/lib.rs @@ -51,7 +51,7 @@ pub use features::RoFeatures; use flate2::bufread::GzEncoder; use flate2::Compression; use meilisearch_types::batches::Batch; -use meilisearch_types::features::{InstanceTogglableFeatures, RuntimeTogglableFeatures}; +use meilisearch_types::features::{InstanceTogglableFeatures, Network, RuntimeTogglableFeatures}; use meilisearch_types::heed::byteorder::BE; use meilisearch_types::heed::types::I128; use meilisearch_types::heed::{self, Env, RoTxn}; @@ -770,7 +770,16 @@ impl IndexScheduler { Ok(()) } - // TODO: consider using a type alias or a struct embedder/template + pub fn put_network(&self, network: Network) -> Result<()> { + let wtxn = self.env.write_txn().map_err(Error::HeedTransaction)?; + self.features.put_network(wtxn, network)?; + Ok(()) + } + + pub fn network(&self) -> Network { + self.features.network() + } + pub fn embedders( &self, index_uid: String, diff --git a/crates/meilisearch/src/routes/features.rs b/crates/meilisearch/src/routes/features.rs index d4e3908d6..33f6c7a60 100644 --- a/crates/meilisearch/src/routes/features.rs +++ b/crates/meilisearch/src/routes/features.rs @@ -193,7 +193,7 @@ async fn patch_features( }; // explicitly destructure for analytics rather than using the `Serialize` implementation, because - // the it renames to camelCase, which we don't want for analytics. + // it renames to camelCase, which we don't want for analytics. // **Do not** ignore fields with `..` or `_` here, because we want to add them in the future. let meilisearch_types::features::RuntimeTogglableFeatures { metrics,