mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-31 07:37:37 +01:00
Network stored in DB
This commit is contained in:
parent
288463093a
commit
350d4eb5b0
@ -1,6 +1,6 @@
|
|||||||
use std::sync::{Arc, RwLock};
|
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::types::{SerdeJson, Str};
|
||||||
use meilisearch_types::heed::{Database, Env, RwTxn};
|
use meilisearch_types::heed::{Database, Env, RwTxn};
|
||||||
|
|
||||||
@ -8,16 +8,18 @@ use crate::error::FeatureNotEnabledError;
|
|||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
/// The number of database used by features
|
/// The number of database used by features
|
||||||
const NUMBER_OF_DATABASES: u32 = 1;
|
const NUMBER_OF_DATABASES: u32 = 2;
|
||||||
/// Database const names for the `FeatureData`.
|
/// Database const names for the `FeatureData`.
|
||||||
mod db_name {
|
mod db_name {
|
||||||
pub const EXPERIMENTAL_FEATURES: &str = "experimental-features";
|
pub const EXPERIMENTAL_FEATURES: &str = "experimental-features";
|
||||||
|
const NETWORK: &str = "network";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct FeatureData {
|
pub(crate) struct FeatureData {
|
||||||
persisted: Database<Str, SerdeJson<RuntimeTogglableFeatures>>,
|
persisted: Database<Str, SerdeJson<RuntimeTogglableFeatures>>,
|
||||||
runtime: Arc<RwLock<RuntimeTogglableFeatures>>,
|
runtime: Arc<RwLock<RuntimeTogglableFeatures>>,
|
||||||
|
network: Arc<RwLock<Network>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@ -111,7 +113,14 @@ impl FeatureData {
|
|||||||
..persisted_features
|
..persisted_features
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Self { persisted: runtime_features_db, runtime })
|
let network_db = runtime_features_db.remap_data_type::<SerdeJson<Network>>();
|
||||||
|
let network: Network = network_db.get(&txn, db_name::NETWORK)?.unwrap_or_default();
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
persisted: runtime_features_db,
|
||||||
|
runtime,
|
||||||
|
network: Arc::new(RwLock::new(network)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_runtime_features(
|
pub fn put_runtime_features(
|
||||||
@ -140,4 +149,21 @@ impl FeatureData {
|
|||||||
pub fn features(&self) -> RoFeatures {
|
pub fn features(&self) -> RoFeatures {
|
||||||
RoFeatures::new(self)
|
RoFeatures::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn put_network(&self, mut wtxn: RwTxn, new_network: Network) -> Result<()> {
|
||||||
|
self.persisted.remap_data_type::<SerdeJson<Network>>().put(
|
||||||
|
&mut wtxn,
|
||||||
|
db_name::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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ pub use features::RoFeatures;
|
|||||||
use flate2::bufread::GzEncoder;
|
use flate2::bufread::GzEncoder;
|
||||||
use flate2::Compression;
|
use flate2::Compression;
|
||||||
use meilisearch_types::batches::Batch;
|
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::byteorder::BE;
|
||||||
use meilisearch_types::heed::types::I128;
|
use meilisearch_types::heed::types::I128;
|
||||||
use meilisearch_types::heed::{self, Env, RoTxn};
|
use meilisearch_types::heed::{self, Env, RoTxn};
|
||||||
@ -770,7 +770,16 @@ impl IndexScheduler {
|
|||||||
Ok(())
|
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(
|
pub fn embedders(
|
||||||
&self,
|
&self,
|
||||||
index_uid: String,
|
index_uid: String,
|
||||||
|
@ -184,7 +184,7 @@ async fn patch_features(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// explicitly destructure for analytics rather than using the `Serialize` implementation, because
|
// 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.
|
// **Do not** ignore fields with `..` or `_` here, because we want to add them in the future.
|
||||||
let meilisearch_types::features::RuntimeTogglableFeatures {
|
let meilisearch_types::features::RuntimeTogglableFeatures {
|
||||||
metrics,
|
metrics,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user