From cda529c07bbae05ae511c64d7fbf00e2b6dde9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 5 Jan 2023 14:25:41 +0100 Subject: [PATCH 1/2] Remove hidden but usable CLI arguments --- .../src/analytics/segment_analytics.rs | 7 +--- meilisearch/src/option.rs | 32 ++++--------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index f95594640..bb36aca25 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -281,12 +281,7 @@ impl From for Infos { ScheduleSnapshot::Enabled(interval) => Some(interval), }; - let IndexerOpts { - log_every_n: _, - max_nb_chunks: _, - max_indexing_memory, - max_indexing_threads, - } = indexer_options; + let IndexerOpts { max_indexing_memory, max_indexing_threads } = indexer_options; // We're going to override every sensible information. // We consider information sensible if it contains a path, an address, or a key. diff --git a/meilisearch/src/option.rs b/meilisearch/src/option.rs index f214cb3bd..a5c258d09 100644 --- a/meilisearch/src/option.rs +++ b/meilisearch/src/option.rs @@ -63,7 +63,7 @@ const DEFAULT_DUMP_DIR: &str = "dumps/"; const MEILI_MAX_INDEXING_MEMORY: &str = "MEILI_MAX_INDEXING_MEMORY"; const MEILI_MAX_INDEXING_THREADS: &str = "MEILI_MAX_INDEXING_THREADS"; -const DEFAULT_LOG_EVERY_N: usize = 100000; +const DEFAULT_LOG_EVERY_N: usize = 100_000; // Each environment (index and task-db) is taking space in the virtual address space. // @@ -88,6 +88,7 @@ pub enum LogLevel { pub struct LogLevelError { pub given_log_level: String, } + impl Display for LogLevelError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!( @@ -97,6 +98,7 @@ impl Display for LogLevelError { ) } } + impl Display for LogLevel { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -109,7 +111,9 @@ impl Display for LogLevel { } } } + impl std::error::Error for LogLevelError {} + impl FromStr for LogLevel { type Err = LogLevelError; @@ -487,16 +491,6 @@ impl Opt { #[derive(Debug, Clone, Parser, Deserialize)] pub struct IndexerOpts { - /// Sets the amount of documents to skip before printing - /// a log regarding the indexing advancement. - #[serde(default = "default_log_every_n")] - #[clap(long, default_value_t = default_log_every_n(), hide = true)] // 100k - pub log_every_n: usize, - - /// Grenad max number of chunks in bytes. - #[clap(long, hide = true)] - pub max_nb_chunks: Option, - /// Sets the maximum amount of RAM Meilisearch can use when indexing. By default, Meilisearch /// uses no more than two thirds of available memory. #[clap(long, env = MEILI_MAX_INDEXING_MEMORY, default_value_t)] @@ -514,12 +508,7 @@ pub struct IndexerOpts { impl IndexerOpts { /// Exports the values to their corresponding env vars if they are not set. pub fn export_to_env(self) { - let IndexerOpts { - max_indexing_memory, - max_indexing_threads, - log_every_n: _, - max_nb_chunks: _, - } = self; + let IndexerOpts { max_indexing_memory, max_indexing_threads } = self; if let Some(max_indexing_memory) = max_indexing_memory.0 { export_to_env_if_not_present( MEILI_MAX_INDEXING_MEMORY, @@ -543,8 +532,7 @@ impl TryFrom<&IndexerOpts> for IndexerConfig { .build()?; Ok(Self { - log_every_n: Some(other.log_every_n), - max_nb_chunks: other.max_nb_chunks, + log_every_n: Some(DEFAULT_LOG_EVERY_N), max_memory: other.max_indexing_memory.map(|b| b.get_bytes() as usize), thread_pool: Some(thread_pool), max_positions_per_attributes: None, @@ -556,8 +544,6 @@ impl TryFrom<&IndexerOpts> for IndexerConfig { impl Default for IndexerOpts { fn default() -> Self { Self { - log_every_n: 100_000, - max_nb_chunks: None, max_indexing_memory: MaxMemory::default(), max_indexing_threads: MaxThreads::default(), } @@ -748,10 +734,6 @@ fn default_dump_dir() -> PathBuf { PathBuf::from(DEFAULT_DUMP_DIR) } -fn default_log_every_n() -> usize { - DEFAULT_LOG_EVERY_N -} - /// Indicates if a snapshot was scheduled, and if yes with which interval. #[derive(Debug, Default, Copy, Clone, Deserialize, Serialize)] pub enum ScheduleSnapshot { From aa4b813237668c09305ae7041cf643089f00202e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 5 Jan 2023 16:00:45 +0100 Subject: [PATCH 2/2] Derive Default on IndexerOpts --- meilisearch/src/option.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/meilisearch/src/option.rs b/meilisearch/src/option.rs index a5c258d09..a60d80d1f 100644 --- a/meilisearch/src/option.rs +++ b/meilisearch/src/option.rs @@ -489,7 +489,7 @@ impl Opt { } } -#[derive(Debug, Clone, Parser, Deserialize)] +#[derive(Debug, Default, Clone, Parser, Deserialize)] pub struct IndexerOpts { /// Sets the maximum amount of RAM Meilisearch can use when indexing. By default, Meilisearch /// uses no more than two thirds of available memory. @@ -541,15 +541,6 @@ impl TryFrom<&IndexerOpts> for IndexerConfig { } } -impl Default for IndexerOpts { - fn default() -> Self { - Self { - max_indexing_memory: MaxMemory::default(), - max_indexing_threads: MaxThreads::default(), - } - } -} - /// A type used to detect the max memory available and use 2/3 of it. #[derive(Debug, Clone, Copy, Deserialize, Serialize)] pub struct MaxMemory(Option);