Merge pull request #662 from meilisearch/database-option-default

implement default on DatabaseOptions
This commit is contained in:
Clément Renault 2020-05-07 17:09:13 +02:00 committed by GitHub
commit 61ce9486fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 35 deletions

View File

@ -463,11 +463,7 @@ fn main() -> Result<(), Box<dyn Error>> {
env_logger::init(); env_logger::init();
let opt = Command::from_args(); let opt = Command::from_args();
let db_opts = DatabaseOptions { let database = Database::open_or_create(opt.path(), DatabaseOptions::default())?;
main_map_size: 100 * 1024 * 1024 * 1024,
update_map_size: 100 * 1024 * 1024 * 1024,
};
let database = Database::open_or_create(opt.path(), db_opts)?;
match opt { match opt {
Command::Index(command) => index_command(command, database), Command::Index(command) => index_command(command, database),

View File

@ -27,6 +27,20 @@ pub struct Database {
update_fn: Arc<ArcSwapFn>, 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 { macro_rules! r#break_try {
($expr:expr, $msg:tt) => { ($expr:expr, $msg:tt) => {
match $expr { match $expr {
@ -135,11 +149,6 @@ fn update_awaiter(
Ok(()) Ok(())
} }
pub struct DatabaseOptions {
pub main_map_size: usize,
pub update_map_size: usize,
}
impl Database { impl Database {
pub fn open_or_create(path: impl AsRef<Path>, options: DatabaseOptions) -> MResult<Database> { pub fn open_or_create(path: impl AsRef<Path>, options: DatabaseOptions) -> MResult<Database> {
let main_path = path.as_ref().join("main"); let main_path = path.as_ref().join("main");
@ -369,16 +378,11 @@ mod tests {
use serde::de::IgnoredAny; use serde::de::IgnoredAny;
use std::sync::mpsc; use std::sync::mpsc;
const DB_OPTS: DatabaseOptions = DatabaseOptions {
main_map_size: 100 * 1024 * 1024 * 1024,
update_map_size: 100 * 1024 * 1024 * 1024,
};
#[test] #[test]
fn valid_updates() { fn valid_updates() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -443,7 +447,7 @@ mod tests {
fn invalid_updates() { fn invalid_updates() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -505,7 +509,7 @@ mod tests {
fn ignored_words_too_long() { fn ignored_words_too_long() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -560,7 +564,7 @@ mod tests {
fn add_schema_attributes_at_end() { fn add_schema_attributes_at_end() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -704,7 +708,7 @@ mod tests {
fn deserialize_documents() { fn deserialize_documents() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -784,7 +788,7 @@ mod tests {
fn partial_document_update() { fn partial_document_update() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -918,7 +922,7 @@ mod tests {
fn delete_index() { fn delete_index() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);
@ -990,7 +994,7 @@ mod tests {
fn check_number_ordering() { fn check_number_ordering() {
let dir = tempfile::tempdir().unwrap(); 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 db = &database;
let (sender, receiver) = mpsc::sync_channel(100); let (sender, receiver) = mpsc::sync_channel(100);

View File

@ -147,11 +147,6 @@ mod tests {
use crate::store::Index; use crate::store::Index;
use meilisearch_schema::Schema; 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 fn set_from_stream<'f, I, S>(stream: I) -> Set
where where
I: for<'a> fst::IntoStreamer<'a, Into = S, Item = &'a [u8]>, 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 { impl<'a> FromIterator<(&'a str, &'a [DocIndex])> for TempDatabase {
fn from_iter<I: IntoIterator<Item = (&'a str, &'a [DocIndex])>>(iter: I) -> Self { fn from_iter<I: IntoIterator<Item = (&'a str, &'a [DocIndex])>>(iter: I) -> Self {
let tempdir = TempDir::new().unwrap(); 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 index = database.create_index("default").unwrap();
let db = &database; let db = &database;

View File

@ -15,16 +15,11 @@ pub struct Server {
data: Data, data: Data,
} }
const DB_OPTS: DatabaseOptions = DatabaseOptions {
main_map_size: 100 * 1024 * 1024 * 1024,
update_map_size: 100 * 1024 * 1024 * 1024,
};
impl Server { impl Server {
pub fn with_uid(uid: &str) -> Server { pub fn with_uid(uid: &str) -> Server {
let tmp_dir = TempDir::new("meilisearch").unwrap(); let tmp_dir = TempDir::new("meilisearch").unwrap();
let default_db_options = DB_OPTS; let default_db_options = DatabaseOptions::default();
let opt = Opt { let opt = Opt {
db_path: tmp_dir.path().to_str().unwrap().to_string(), db_path: tmp_dir.path().to_str().unwrap().to_string(),