Introduce the UpdateBuilder and use it in the HTTP routes

This commit is contained in:
Clément Renault 2020-10-26 20:18:10 +01:00 committed by Kerollmops
parent 5c62fbb6a8
commit 3889d956d9
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
8 changed files with 641 additions and 537 deletions

View file

@ -1,35 +1,37 @@
use std::borrow::Cow;
use std::convert::TryFrom;
use fst::{IntoStreamer, Streamer};
use grenad::CompressionType;
use itertools::Itertools;
use roaring::RoaringBitmap;
use crate::{Index, BEU32};
use crate::Index;
use super::clear_documents::ClearDocuments;
use super::delete_documents::DeleteDocuments;
use super::index_documents::IndexDocuments;
pub struct UpdateBuilder {
log_every_n: usize,
max_nb_chunks: Option<usize>,
max_memory: usize,
linked_hash_map_size: usize,
chunk_compression_type: CompressionType,
chunk_compression_level: Option<u32>,
chunk_fusing_shrink_size: u64,
enable_chunk_fusing: bool,
indexing_jobs: Option<usize>,
pub(crate) log_every_n: Option<usize>,
pub(crate) max_nb_chunks: Option<usize>,
pub(crate) max_memory: Option<usize>,
pub(crate) linked_hash_map_size: Option<usize>,
pub(crate) chunk_compression_type: CompressionType,
pub(crate) chunk_compression_level: Option<u32>,
pub(crate) chunk_fusing_shrink_size: Option<u64>,
pub(crate) indexing_jobs: Option<usize>,
}
impl UpdateBuilder {
pub fn new() -> UpdateBuilder {
todo!()
UpdateBuilder {
log_every_n: None,
max_nb_chunks: None,
max_memory: None,
linked_hash_map_size: None,
chunk_compression_type: CompressionType::None,
chunk_compression_level: None,
chunk_fusing_shrink_size: None,
indexing_jobs: None,
}
}
pub fn log_every_n(&mut self, log_every_n: usize) -> &mut Self {
self.log_every_n = log_every_n;
self.log_every_n = Some(log_every_n);
self
}
@ -39,12 +41,12 @@ impl UpdateBuilder {
}
pub fn max_memory(&mut self, max_memory: usize) -> &mut Self {
self.max_memory = max_memory;
self.max_memory = Some(max_memory);
self
}
pub fn linked_hash_map_size(&mut self, linked_hash_map_size: usize) -> &mut Self {
self.linked_hash_map_size = linked_hash_map_size;
self.linked_hash_map_size = Some(linked_hash_map_size);
self
}
@ -59,12 +61,7 @@ impl UpdateBuilder {
}
pub fn chunk_fusing_shrink_size(&mut self, chunk_fusing_shrink_size: u64) -> &mut Self {
self.chunk_fusing_shrink_size = chunk_fusing_shrink_size;
self
}
pub fn enable_chunk_fusing(&mut self, enable_chunk_fusing: bool) -> &mut Self {
self.enable_chunk_fusing = enable_chunk_fusing;
self.chunk_fusing_shrink_size = Some(chunk_fusing_shrink_size);
self
}
@ -97,6 +94,33 @@ impl UpdateBuilder {
index: &'i Index,
) -> IndexDocuments<'t, 'u, 'i>
{
IndexDocuments::new(wtxn, index)
let mut builder = IndexDocuments::new(wtxn, index);
if let Some(log_every_n) = self.log_every_n {
builder.log_every_n(log_every_n);
}
if let Some(max_nb_chunks) = self.max_nb_chunks {
builder.max_nb_chunks(max_nb_chunks);
}
if let Some(max_memory) = self.max_memory {
builder.max_memory(max_memory);
}
if let Some(linked_hash_map_size) = self.linked_hash_map_size {
builder.linked_hash_map_size(linked_hash_map_size);
}
builder.chunk_compression_type(self.chunk_compression_type);
if let Some(chunk_compression_level) = self.chunk_compression_level {
builder.chunk_compression_level(chunk_compression_level);
}
if let Some(chunk_fusing_shrink_size) = self.chunk_fusing_shrink_size {
builder.chunk_fusing_shrink_size(chunk_fusing_shrink_size);
}
if let Some(indexing_jobs) = self.indexing_jobs {
builder.indexing_jobs(indexing_jobs);
}
builder
}
}