2021-08-16 19:43:06 +08:00
|
|
|
use milli::update::UpdateBuilder;
|
2021-09-03 00:18:59 +08:00
|
|
|
use milli::CompressionType;
|
2021-02-27 17:19:05 +08:00
|
|
|
use rayon::ThreadPool;
|
|
|
|
|
2021-09-21 19:23:22 +08:00
|
|
|
use crate::options::IndexerOpts;
|
2021-02-27 17:19:05 +08:00
|
|
|
|
|
|
|
pub struct UpdateHandler {
|
|
|
|
max_nb_chunks: Option<usize>,
|
|
|
|
chunk_compression_level: Option<u32>,
|
|
|
|
thread_pool: ThreadPool,
|
|
|
|
log_frequency: usize,
|
2021-09-03 00:18:59 +08:00
|
|
|
max_memory: Option<usize>,
|
2021-02-27 17:19:05 +08:00
|
|
|
chunk_compression_type: CompressionType,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateHandler {
|
2021-06-15 23:39:07 +08:00
|
|
|
pub fn new(opt: &IndexerOpts) -> anyhow::Result<Self> {
|
2021-02-27 17:19:05 +08:00
|
|
|
let thread_pool = rayon::ThreadPoolBuilder::new()
|
2021-06-28 20:35:50 +08:00
|
|
|
.num_threads(opt.indexing_jobs.unwrap_or(num_cpus::get() / 2))
|
2021-02-27 17:19:05 +08:00
|
|
|
.build()?;
|
2021-09-03 00:18:59 +08:00
|
|
|
|
2021-02-27 17:19:05 +08:00
|
|
|
Ok(Self {
|
|
|
|
max_nb_chunks: opt.max_nb_chunks,
|
|
|
|
chunk_compression_level: opt.chunk_compression_level,
|
|
|
|
thread_pool,
|
|
|
|
log_frequency: opt.log_every_n,
|
2021-09-03 00:18:59 +08:00
|
|
|
max_memory: opt.max_memory.map(|m| m.get_bytes() as usize),
|
2021-02-27 17:19:05 +08:00
|
|
|
chunk_compression_type: opt.chunk_compression_type,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-27 04:52:06 +08:00
|
|
|
pub fn update_builder(&self, update_id: u64) -> UpdateBuilder {
|
2021-02-27 17:19:05 +08:00
|
|
|
// We prepare the update by using the update builder.
|
|
|
|
let mut update_builder = UpdateBuilder::new(update_id);
|
|
|
|
if let Some(max_nb_chunks) = self.max_nb_chunks {
|
|
|
|
update_builder.max_nb_chunks(max_nb_chunks);
|
|
|
|
}
|
|
|
|
if let Some(chunk_compression_level) = self.chunk_compression_level {
|
|
|
|
update_builder.chunk_compression_level(chunk_compression_level);
|
|
|
|
}
|
|
|
|
update_builder.thread_pool(&self.thread_pool);
|
|
|
|
update_builder.log_every_n(self.log_frequency);
|
2021-09-03 00:18:59 +08:00
|
|
|
if let Some(max_memory) = self.max_memory {
|
|
|
|
update_builder.max_memory(max_memory);
|
|
|
|
}
|
2021-02-27 17:19:05 +08:00
|
|
|
update_builder.chunk_compression_type(self.chunk_compression_type);
|
|
|
|
update_builder
|
|
|
|
}
|
|
|
|
}
|