mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 08:41:00 +00:00
Parameterize growth factor and index count
This commit is contained in:
@ -35,7 +35,10 @@ pub struct IndexMapper {
|
|||||||
|
|
||||||
/// Path to the folder where the LMDB environments of each index are.
|
/// Path to the folder where the LMDB environments of each index are.
|
||||||
base_path: PathBuf,
|
base_path: PathBuf,
|
||||||
index_size: usize,
|
/// The map size an index is opened with on the first time.
|
||||||
|
index_base_map_size: usize,
|
||||||
|
/// The quantity by which the map size of an index is incremented upon reopening, in bytes.
|
||||||
|
index_growth_amount: usize,
|
||||||
pub indexer_config: Arc<IndexerConfig>,
|
pub indexer_config: Arc<IndexerConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,14 +174,17 @@ impl IndexMapper {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
env: &Env,
|
env: &Env,
|
||||||
base_path: PathBuf,
|
base_path: PathBuf,
|
||||||
index_size: usize,
|
index_base_map_size: usize,
|
||||||
|
index_growth_amount: usize,
|
||||||
|
index_count: usize,
|
||||||
indexer_config: IndexerConfig,
|
indexer_config: IndexerConfig,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
index_map: Arc::new(RwLock::new(IndexMap::new(20))),
|
index_map: Arc::new(RwLock::new(IndexMap::new(index_count))),
|
||||||
index_mapping: env.create_database(Some(INDEX_MAPPING))?,
|
index_mapping: env.create_database(Some(INDEX_MAPPING))?,
|
||||||
base_path,
|
base_path,
|
||||||
index_size,
|
index_base_map_size,
|
||||||
|
index_growth_amount,
|
||||||
indexer_config: Arc::new(indexer_config),
|
indexer_config: Arc::new(indexer_config),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -221,7 +227,8 @@ impl IndexMapper {
|
|||||||
let index_path = self.base_path.join(uuid.to_string());
|
let index_path = self.base_path.join(uuid.to_string());
|
||||||
fs::create_dir_all(&index_path)?;
|
fs::create_dir_all(&index_path)?;
|
||||||
|
|
||||||
let index = self.create_or_open_index(&index_path, date, self.index_size)?;
|
let index =
|
||||||
|
self.create_or_open_index(&index_path, date, self.index_base_map_size)?;
|
||||||
|
|
||||||
wtxn.commit()?;
|
wtxn.commit()?;
|
||||||
// Error if the UUIDv4 somehow already exists in the map, since it should be fresh.
|
// Error if the UUIDv4 somehow already exists in the map, since it should be fresh.
|
||||||
@ -324,7 +331,7 @@ impl IndexMapper {
|
|||||||
|
|
||||||
let resize_succeeded = (move || {
|
let resize_succeeded = (move || {
|
||||||
let current_size = index.map_size()?;
|
let current_size = index.map_size()?;
|
||||||
let new_size = current_size * 2;
|
let new_size = current_size + self.index_growth_amount;
|
||||||
let closing_event = index.prepare_for_closing();
|
let closing_event = index.prepare_for_closing();
|
||||||
|
|
||||||
log::debug!("Waiting for index {name} to close");
|
log::debug!("Waiting for index {name} to close");
|
||||||
@ -400,8 +407,11 @@ impl IndexMapper {
|
|||||||
None => {
|
None => {
|
||||||
let index_path = self.base_path.join(uuid.to_string());
|
let index_path = self.base_path.join(uuid.to_string());
|
||||||
|
|
||||||
let index =
|
let index = self.create_or_open_index(
|
||||||
self.create_or_open_index(&index_path, None, self.index_size)?;
|
&index_path,
|
||||||
|
None,
|
||||||
|
self.index_base_map_size,
|
||||||
|
)?;
|
||||||
match index_map.insert(&uuid, index.clone()) {
|
match index_map.insert(&uuid, index.clone()) {
|
||||||
InsertionOutcome::InsertedNew => break (index, None),
|
InsertionOutcome::InsertedNew => break (index, None),
|
||||||
InsertionOutcome::Evicted(evicted_uuid, evicted_index) => {
|
InsertionOutcome::Evicted(evicted_uuid, evicted_index) => {
|
||||||
|
@ -231,8 +231,12 @@ pub struct IndexSchedulerOptions {
|
|||||||
pub dumps_path: PathBuf,
|
pub dumps_path: PathBuf,
|
||||||
/// The maximum size, in bytes, of the task index.
|
/// The maximum size, in bytes, of the task index.
|
||||||
pub task_db_size: usize,
|
pub task_db_size: usize,
|
||||||
/// The maximum size, in bytes, of each meilisearch index.
|
/// The size, in bytes, with which a meilisearch index is opened the first time of each meilisearch index.
|
||||||
pub index_size: usize,
|
pub index_base_map_size: usize,
|
||||||
|
/// The size, in bytes, by which the map size of an index is increased when it resized due to being full.
|
||||||
|
pub index_growth_amount: usize,
|
||||||
|
/// The number of indexes that can be concurrently opened in memory.
|
||||||
|
pub index_count: usize,
|
||||||
/// Configuration used during indexing for each meilisearch index.
|
/// Configuration used during indexing for each meilisearch index.
|
||||||
pub indexer_config: IndexerConfig,
|
pub indexer_config: IndexerConfig,
|
||||||
/// Set to `true` iff the index scheduler is allowed to automatically
|
/// Set to `true` iff the index scheduler is allowed to automatically
|
||||||
@ -384,7 +388,9 @@ impl IndexScheduler {
|
|||||||
index_mapper: IndexMapper::new(
|
index_mapper: IndexMapper::new(
|
||||||
&env,
|
&env,
|
||||||
options.indexes_path,
|
options.indexes_path,
|
||||||
options.index_size,
|
options.index_base_map_size,
|
||||||
|
options.index_growth_amount,
|
||||||
|
options.index_count,
|
||||||
options.indexer_config,
|
options.indexer_config,
|
||||||
)?,
|
)?,
|
||||||
env,
|
env,
|
||||||
@ -1164,7 +1170,9 @@ mod tests {
|
|||||||
snapshots_path: tempdir.path().join("snapshots"),
|
snapshots_path: tempdir.path().join("snapshots"),
|
||||||
dumps_path: tempdir.path().join("dumps"),
|
dumps_path: tempdir.path().join("dumps"),
|
||||||
task_db_size: 1000 * 1000, // 1 MB, we don't use MiB on purpose.
|
task_db_size: 1000 * 1000, // 1 MB, we don't use MiB on purpose.
|
||||||
index_size: 1000 * 1000, // 1 MB, we don't use MiB on purpose.
|
index_base_map_size: 1000 * 1000, // 1 MB, we don't use MiB on purpose.
|
||||||
|
index_growth_amount: 1000 * 1000, // 1 MB
|
||||||
|
index_count: 5,
|
||||||
indexer_config: IndexerConfig::default(),
|
indexer_config: IndexerConfig::default(),
|
||||||
autobatching_enabled,
|
autobatching_enabled,
|
||||||
};
|
};
|
||||||
|
@ -205,9 +205,11 @@ fn open_or_create_database_unchecked(
|
|||||||
snapshots_path: opt.snapshot_dir.clone(),
|
snapshots_path: opt.snapshot_dir.clone(),
|
||||||
dumps_path: opt.dump_dir.clone(),
|
dumps_path: opt.dump_dir.clone(),
|
||||||
task_db_size: opt.max_task_db_size.get_bytes() as usize,
|
task_db_size: opt.max_task_db_size.get_bytes() as usize,
|
||||||
index_size: opt.max_index_size.get_bytes() as usize,
|
index_base_map_size: opt.max_index_size.get_bytes() as usize,
|
||||||
indexer_config: (&opt.indexer_options).try_into()?,
|
indexer_config: (&opt.indexer_options).try_into()?,
|
||||||
autobatching_enabled: true,
|
autobatching_enabled: true,
|
||||||
|
index_growth_amount: byte_unit::Byte::from_str("10GiB").unwrap().get_bytes() as usize,
|
||||||
|
index_count: 20,
|
||||||
})?)
|
})?)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user