mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
Merge pull request #662 from meilisearch/database-option-default
implement default on DatabaseOptions
This commit is contained in:
commit
61ce9486fc
@ -463,11 +463,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::init();
|
||||
|
||||
let opt = Command::from_args();
|
||||
let db_opts = DatabaseOptions {
|
||||
main_map_size: 100 * 1024 * 1024 * 1024,
|
||||
update_map_size: 100 * 1024 * 1024 * 1024,
|
||||
};
|
||||
let database = Database::open_or_create(opt.path(), db_opts)?;
|
||||
let database = Database::open_or_create(opt.path(), DatabaseOptions::default())?;
|
||||
|
||||
match opt {
|
||||
Command::Index(command) => index_command(command, database),
|
||||
|
@ -27,6 +27,20 @@ pub struct Database {
|
||||
update_fn: Arc<ArcSwapFn>,
|
||||
}
|
||||
|
||||
pub struct DatabaseOptions {
|
||||
pub main_map_size: usize,
|
||||
pub update_map_size: usize,
|
||||
}
|
||||
|
||||
impl Default for DatabaseOptions {
|
||||
fn default() -> DatabaseOptions {
|
||||
DatabaseOptions {
|
||||
main_map_size: 100 * 1024 * 1024 * 1024, //100Gb
|
||||
update_map_size: 100 * 1024 * 1024 * 1024, //100Gb
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! r#break_try {
|
||||
($expr:expr, $msg:tt) => {
|
||||
match $expr {
|
||||
@ -135,11 +149,6 @@ fn update_awaiter(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct DatabaseOptions {
|
||||
pub main_map_size: usize,
|
||||
pub update_map_size: usize,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn open_or_create(path: impl AsRef<Path>, options: DatabaseOptions) -> MResult<Database> {
|
||||
let main_path = path.as_ref().join("main");
|
||||
@ -369,16 +378,11 @@ mod tests {
|
||||
use serde::de::IgnoredAny;
|
||||
use std::sync::mpsc;
|
||||
|
||||
const DB_OPTS: DatabaseOptions = DatabaseOptions {
|
||||
main_map_size: 100 * 1024 * 1024 * 1024,
|
||||
update_map_size: 100 * 1024 * 1024 * 1024,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn valid_updates() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -443,7 +447,7 @@ mod tests {
|
||||
fn invalid_updates() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -505,7 +509,7 @@ mod tests {
|
||||
fn ignored_words_too_long() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -560,7 +564,7 @@ mod tests {
|
||||
fn add_schema_attributes_at_end() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -704,7 +708,7 @@ mod tests {
|
||||
fn deserialize_documents() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -784,7 +788,7 @@ mod tests {
|
||||
fn partial_document_update() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -918,7 +922,7 @@ mod tests {
|
||||
fn delete_index() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Arc::new(Database::open_or_create(dir.path(), DB_OPTS).unwrap());
|
||||
let database = Arc::new(Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap());
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
@ -990,7 +994,7 @@ mod tests {
|
||||
fn check_number_ordering() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
let database = Database::open_or_create(dir.path(), DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(dir.path(), DatabaseOptions::default()).unwrap();
|
||||
let db = &database;
|
||||
|
||||
let (sender, receiver) = mpsc::sync_channel(100);
|
||||
|
@ -147,11 +147,6 @@ mod tests {
|
||||
use crate::store::Index;
|
||||
use meilisearch_schema::Schema;
|
||||
|
||||
const DB_OPTS: DatabaseOptions = DatabaseOptions {
|
||||
main_map_size: 100 * 1024 * 1024 * 1024,
|
||||
update_map_size: 100 * 1024 * 1024 * 1024,
|
||||
};
|
||||
|
||||
fn set_from_stream<'f, I, S>(stream: I) -> Set
|
||||
where
|
||||
I: for<'a> fst::IntoStreamer<'a, Into = S, Item = &'a [u8]>,
|
||||
@ -254,7 +249,7 @@ mod tests {
|
||||
impl<'a> FromIterator<(&'a str, &'a [DocIndex])> for TempDatabase {
|
||||
fn from_iter<I: IntoIterator<Item = (&'a str, &'a [DocIndex])>>(iter: I) -> Self {
|
||||
let tempdir = TempDir::new().unwrap();
|
||||
let database = Database::open_or_create(&tempdir, DB_OPTS).unwrap();
|
||||
let database = Database::open_or_create(&tempdir, DatabaseOptions::default()).unwrap();
|
||||
let index = database.create_index("default").unwrap();
|
||||
|
||||
let db = &database;
|
||||
|
@ -15,16 +15,11 @@ pub struct Server {
|
||||
data: Data,
|
||||
}
|
||||
|
||||
const DB_OPTS: DatabaseOptions = DatabaseOptions {
|
||||
main_map_size: 100 * 1024 * 1024 * 1024,
|
||||
update_map_size: 100 * 1024 * 1024 * 1024,
|
||||
};
|
||||
|
||||
impl Server {
|
||||
pub fn with_uid(uid: &str) -> Server {
|
||||
let tmp_dir = TempDir::new("meilisearch").unwrap();
|
||||
|
||||
let default_db_options = DB_OPTS;
|
||||
let default_db_options = DatabaseOptions::default();
|
||||
|
||||
let opt = Opt {
|
||||
db_path: tmp_dir.path().to_str().unwrap().to_string(),
|
||||
|
Loading…
Reference in New Issue
Block a user